sort and uniq
sort orders lines. uniq collapses neighbours so sort first. -c counts and -rn sorts numbers descending.
Example
printf "b\na\nb\nc\nb\n" | sort | uniq -c | sort -rn
printf "10\n9\n100\n" | sort -n
printf "a\na\nb\n" | sort -uResult
3 b
1 c
1 a
9
10
100
a
bExercise
Count duplicates.
uniq Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.