uniq
Report or omit repeated lines
Overview
Filters adjacent matching lines from INPUT (or standard input), writing to OUTPUT (or standard output). Note: uniq does not detect repeated lines unless they are adjacent. You may need to sort the input first.
Syntax
uniq [OPTION]... [INPUT [OUTPUT]]Common Options
-c, --countPrefix lines by the number of occurrences.
-d, --repeatedOnly print duplicate lines, one for each group.
-D, --all-repeated[=delimit-method]Print all duplicate lines (delimit-method can be 'none' (default), 'prepend', or 'separate').
-f N, --skip-fields=NAvoid comparing the first N fields.
-i, --ignore-caseIgnore differences in case when comparing.
-s N, --skip-chars=NAvoid comparing the first N characters.
-u, --uniqueOnly print unique lines.
-w N, --check-chars=NCompare no more than N characters in lines.
Examples
Sorts data.txt and then removes adjacent duplicate lines.
Sorts words.txt, removes duplicates, and shows the count of each line.
Sorts items.txt and shows only the lines that were repeated.
Sorts log.txt and shows only the lines that appeared exactly once.
Sorts users.csv by the second field, then finds unique lines ignoring the first field and case.