Display only the largest number in the head

I am using sort -r | head and do like this:

  8 a1
  8 a2
  5 a3
  5 a4
  4 a5
  4 a6
  4 a7
  4 a8
  4 a9
  4 a0

      

What can I do to make the output like this:

  8 a1
  8 a2

      

only the largest number k1 appears ????

+3


source to share


1 answer


There are several ways to do this, but it is used here awk

. Since it's already sorted, you want to check to just print the lines that match the first value, by connecting the head

ed list to something like



awk 'BEGIN{maxval=0}; (maxval==0) {maxval=$1}; ($1==maxval) {print $0}'

      

+3


source







All Articles