Unix command "uniq" & "sort"

eleven picture eleven · Oct 1, 2012 · Viewed 7.8k times · Source

As we known

uniq [options] [file1 [file2]]

It remove duplicate adjacent lines from sorted file1. The option -c prints each line once, counting instances of each. So if we have the following result:

     34 Operating System
    254 Data Structure
      5 Crypo
     21 C++
   1435 C Language
    589 Java 1.6

And we sort above data using "sort -1knr", the result is as below:

   1435 C Language
    589 Java 1.6
    254 Data Structure
     34 Operating System
     21 C++
      5 Crypo

Can anyone help me out that how to output only the book name in this order (no number)?

Answer

Barmar picture Barmar · Oct 1, 2012
uniq -c filename | sort -k 1nr | awk '{$1='';print}'