uniq
Official Description
Removes or lists repeated lines in a file.
Syntax
uniq [-cdu] [-f fields] [-s chars] [input-file [output-file]]
Options
-c displays the count of occurrences of the line.
-d displays repeated lines only.
-f fields ignores specified fields when comparing lines.
-s chars ignores the specified number of chars when doing comparisons.
-u displays unique lines only.
Oddities
Repeated lines must be on consecutive lines to be found.
You can arrange them with the sort command before processing.
Example
$ uniq utest den cheryl cheryl cheryl den mark # Mark shows up once den den cheryl dencheryl den cheryl $ $ uniq -c utest 1 den 1 cheryl 1 cheryl cheryl den 3 mark # There were four lines of mark 1 den 1 den cheryl 1 dencheryl ...
Get Korn Shell Programming by Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.