Count each distinct line; uniq compares adjacent lines.
sort names.txt | uniq -cReport or remove adjacent repeated lines; sort first to group matches.
uniq [OPTION]... [INPUT [OUTPUT]]Count each distinct line; uniq compares adjacent lines.
sort names.txt | uniq -cPrint values that occur more than once.
sort names.txt | uniq -d| Option / clause | Description |
|---|---|
-c, --count | Prefix each output line with its number of occurrences. |
-d, --repeated | Print only repeated lines. |
-u, --unique | Print only lines that occur once. |
-i, --ignore-case | Ignore case when comparing lines. |
-f, --skip-fields=N | Skip N fields before comparing. |
-s, --skip-chars=N | Skip N characters before comparing. |
Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.