Use -n
in your sort
command, so that it sorts numerically. Also -r
allows you to reverse the result:
$ sort test.txt | uniq -c | sort -n
1 ada
1 ccd
1 cd
1 nnaa
2 aaa
2 bbb
4 aa
10 naa
$ sort test.txt | uniq -c | sort -nr
10 naa
4 aa
2 bbb
2 aaa
1 nnaa
1 cd
1 ccd
1 ada
From man sort
:
-n, --numeric-sort
compare according to string numerical value
-r, --reverse
reverse the result of comparisons