Get the App
SLTechnology News&Howtos  ›  Servers  › 

The usage of the Linux basic command uniq

Shulou Source: shulou.com Published: 2022-06-01 12:37:48 09月10日 Update

This article introduces the relevant knowledge of "the usage of the Linux basic command uniq". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Uniq

The repeated lines in the file are deleted and the results are sent to standard output or the specified file. Before using the uniq directive, you must use sort to sort the content, otherwise it has no effect. If there is no option, the matching rows are merged into the first match.

The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.

1. Grammar

Uniq [options] [input] [output]

2. List of options

Option

Description

-- version

Display command version information

-- help

Show help documentation

-c |-- count

Displays the number of times the row is repeated

-d |-- repeated

Show only recurring lines

-D |-- all-repeated [= delimit-method]

Print all duplicate lines

-f |-- skip-fields=N

Ignore the first n fields

-I |-- ignore-case

Ignore case when comparing

-s |-- skip-chars=N

Ignore the first n characters

-u |-- unique

Show only rows that do not repeat

-z |-- zero-terminated

Finishes with 0 bytes instead of newline

-w |-- check-chars=N

The comparison does not exceed the specified number of times

3. Examples

1) Delete duplicate lines

[root@192 weijie] # cat 3.c / / View content

Nihao linux.

I am david.

Nihao linux.

I am david.

[root@192 weijie] # sort 3.c | uniq-c / / sort first, and then delete duplicate rows, showing the number of duplicate rows

2 i am david.

2 nihao linux.

2) only rows that do not repeat are displayed

[root@localhost weijie] # cat 3.c / / View content

Nihao linux.

I am david.

Nihao linux.

I am david.

I love linux

[root@localhost weijie] # sort 3.c | uniq-c-u / / displays only lines that do not repeat

1 i love linux

This is the end of the introduction to "the usage of the Linux basic command uniq". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Commands content times basics files more knowledge sorting output practicality learning next information dilemma size fields characters bytes instances actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi NVidia Microsoft Shulou Information