Tsallaka zuwa abun ciki
Justice Tech School

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 -u

Result

      3 b
      1 c
      1 a
9
10
100
a
b

Exercise

Count duplicates.

uniq 

Quiz Test

Why sort before uniq?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.