output one copy of each line in input.txt uniq input.txt
count occurrences of lines uniq -c count.txt
output only lines that are duplicated uniq -d repeats.txt
output only the lines that are not repeated in unique.txt uniq -u unique.txt
output unique lines ignoring case uniq -i case.txt
Output a single copy of each unique line in a file: uniq
Output the unique lines from the given input or file.
Since it does not detect repeated lines unless they are adjacent, we need to sort them first.
-
Display each line once:
sort file | uniq
-
Display only unique lines:
sort file | uniq -u
-
Display only duplicate lines:
sort file | uniq -d
-
Display number of occurrences of each line along with that line:
sort file | uniq -c
-
Display number of occurrences of each line, sorted by the most frequent:
sort file | uniq -c | sort -nr
sort | uniq
sort | uniq -u
sort | uniq -d
sort | uniq -c
sort | uniq -uc
sort | uniq -dc