-1

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 ??

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
Vin
  • 51
  • 1
  • 6

2 Answers2

1

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}'

or

sar -d -f sa28 | awk '{print $3, $4}' | sort -k2,2n | tail -n 1
Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
0

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

Danila Ladner
  • 5,241
  • 21
  • 30