Linux command: uniq

Quick startuniqCommand to handle duplicate records/lines in the text

uniqIt is a command used to sort text lines.

You can get these lines from a file, or use a pipe from the output of another command:

uniq dogs.txt

ls | uniq

You need to consider the following key things:uniqOnly adjacent duplicate rows will be detected.

This means you are most likely to combine it withsort:

sort dogs.txt | uniq

ThissortThis command has its own way to delete duplicates-u(Unique) Option. butuniqThere is more power.

By default, it deletes duplicate rows:

You can tell it to show only duplicate rows, for example, use-dOptions:

sort dogs.txt | uniq -d

you can use it-uOptions to show only non-repeating lines:

you can use it-cOptions:

Use special combinations:

sort dogs.txt | uniq -c | sort -nr

Then sort the rows in the most common order:

ThisuniqThis command can be used in Linux, macOS, WSL and wherever you have a UNIX environment

Download mine for freeLinux Command Manual


More cli tutorials: