Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using awk to find out DEVICE on which read per second (rd_sec/s) is highest, (from SAR file) below is my command :

# sar -d -f sa28 | awk '{print $3,$4}' |sort -k1,1n 

Output is showing on console with sorted manner, But I want the exact one entry whose rd_sec/s is highest.

Output is something like this :

dev8-0 9.92
dev8-0 9.92
dev8-0 9.93
dev8-0 9.94
dev8-0 9.94
dev8-0 9.96
dev8-0 9.98
dev8-0 9.98
dev8-0 9.98
dev8-0 9.98
dev8-0 9.98
dev8-0 9.99

How can I do that ? whats the changes in the command ??

share|improve this question

You can remove the sort command (and you won't need tail):

sar -d -f sa28 | awk '$4 > entries[$3] {entries[$3] = $4} END {for (entry in entries) {print entry, entries[entry]}}'

This will print the highest value for each device.

If you want to find the one highest entry among all:

sar -d -f sa28 | awk '$4 > highest {highest = $4; device = $3} END {print device, highest}'


sar -d -f sa28 | awk '{print $3, $4}' | sort -k2,2n | tail -n 1
share|improve this answer

you need to pipe your result into "tail -1"

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.