cheat:uniq
# To show all lines without duplication:
# (`sort -u` and `uniq` have the same effect.)
sort <file> | uniq
# To show not duplicated lines:
sort <file> | uniq -u
# To show duplicated lines only:
sort <file> | uniq -d
# To count all lines:
sort <file> | uniq -c
# To count not duplicated lines:
sort <file> | uniq -uc
# To count only duplicated lines:
sort <file> | uniq -dc
tldr:uniq
# 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.
# More information: <https://www.gnu.org/software/coreutils/uniq>.
# Display each line once:
sort path/to/file | uniq
# Display only unique lines:
sort path/to/file | uniq -u
# Display only duplicate lines:
sort path/to/file | uniq -d
# Display number of occurrences of each line along with that line:
sort path/to/file | uniq -c
# Display number of occurrences of each line, sorted by the most frequent:
sort path/to/file | uniq -c | sort -nr
$
cheat.sh