How to do natural sort output of “uniq -c” in descending/acsending order? – unix

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)