top 10 highest and lowest percentile from a column

Hi, I want to extract the the top 10 and lowest 10 percentile for a column of values.

For example in column 2 for this file:

JOE   1 
JAY   5
JAM   6
JIL   8
JIB   4
JIH   3
JIG   2
JIT   7
JAM   9
MAR   10

The top 10 lowest will be:

JOE   1

and the top 10 highest will be:

MAR 10

If there is a quick way of doing this then it would be great

Thanks

I looked for the:
bottom of top 5 (since 10 seemed weird with only 10 records)
top 1

$ sort -k2n <sample9.txt | head -5 | tail -1
JAY   5

$ sort -k2n <sample9.txt | head -1
JOE   1

You could use the following:

Highest
sort -rn -k2 file | head -n1

Lowest
sort -n -k2 file | head -n1

If you need more lines displayed just change the number in the head command (i.e. to display 10 lines use head -n10).

Hope this helps.

1 Like