sort / uniq
bash
sort file # sort lines (lexicographically)
sort -n file # as numbers
sort -rn file # descending (numbers)
sort -h file # human-readable sizes (2K, 1G)
sort -k2 file # by the 2nd field
sort -t: -k3 -n /etc/passwd # ":" delimiter, by the 3rd field, numerically
sort -u file # sort + remove duplicates
sort -c file # check whether it's already sorted
uniq file # remove ADJACENT duplicates (needs sort first!)
sort file | uniq -c # count how many times each line repeats
sort file | uniq -c | sort -rn # top by frequency
sort file | uniq -d # only repeated lines ; -u — only unique ones