finding greatest value in a column using awk from iostat output in linux

Friends,
Need some help.
On linux i have to run iostat command and in each iteration have to print the greatest value in each column.

e.g

iostat -dt -kx 2 2 | awk ' !/sd[a-z][0-9]/ &&!/%util/ && !/Time/ && !/Linux/ {print $12}'

4.38
0.00

0.00
0.00

WHhat i would like to print is only the greatest value in each iteration. Can someone pls help me with this.

Two things:

iostat -dt -kx 2 2 | awk ' !/sd[a-z][0-9]/ &&!/%util/ && !/Time/ && !/Linux/ {print $12}' | sort | tail -1
iostat -dt -kx 2 2 | awk ' !/sd[a-z][0-9]/ &&!/%util/ && !/Time/ && !/Linux/ {if(max < $12)max=$12}END{print max}' 

cheers,
Devaraj Takhellambam

iostat -dt -kx 2 2 | awk ' !/sd[a-z][0-9]/ &&!/%util/ && !/Time/ && !/Linux/ {print $12}' | awk 'BEGIN {max = 0.00} {if ($0>max) max=$0} END {print max}' 

I hope this works, but i am not sure. Try it out and let me know.

its not working. neither code is working. first one is print only 1 value at the end of all the iterations and so does code 2. but i need the values at the end of each iteration.

Did you try this one... ???

iostat -dt -kx 2 2 | awk ' !/sd[a-z][0-9]/ &&!/%util/ && !/Time/ && !/Linux/ {print $12}' | awk 'BEGIN {max = 0.00} {if ($0>max) max=$0} END {print max}' 
iostat -dt -kx 2 2 | awk ' !/sd[a-z][0-9]/ &&!/%util/ && !/Time/ && !/Linux/ {print $12}' | 
awk 'BEGIN {max = 0.00} {if ($0>max) max=$0} END {print max}'

6.05

This fulfils your requirement rite ???

actually no. this values should be printed at each iteration

for example u run iostat -dtx 2 2 (i.e two iterations at 2 seconds interval) so after the first iteration is over, the max value will be printed, again on the 2 nd iteration the new max value and so on. hope i am clear.

Try this one...

iostat -dt -kx 2 2 | awk 'BEGIN {max = 0.00} !/sd[a-z][0-9]/ &&!/%util/ && !/Time/ && !/Linux/ {if ($12>max) max=$12} END {print max}' 

same result :frowning:

 iostat -dt -kx 2 2 | awk 'BEGIN {max = 0.00} !/sd[a-z][0-9]/ &&!/%util/ && !/Time/ && !/Linux/ {if ($12>max) max=$12} END {print max}'
4.38

In that case, load the results into a tem file and use the logic to get the max value for each iteration. Way to go..

wont it become too hectic !!!!1

i think that devtakh is right ! try to read the results from temp file
and it will not become too hectic !

there is a small problem, it will treat all the entries as 1 column. so same problem comes back again.

Ok, try this then

iostat -dt -kx 2 2 | sed  '/^Linux.*/{N;d}' | awk 'BEGIN{i=max=0}$1 == "sda"{print $12;if ($12 > max)max=$12;next}$0 ~ /^$/{print "Iteration:",i,"Value is:",max;max=0;i+=1;next}'

cheers,
Devaraj Takhellambam

not working as in a multi disked linux system, this will fail. also i dont want to use sed. only awk.

---------- Post updated 03-03-10 at 12:01 AM ---------- Previous update was 03-02-10 at 10:47 AM ----------

Achieved the solution. here its is

 iostat -dtx 5 5 | awk 'BEGIN {max=0} !/sd[a-z][0-9]/ && !/Device/ && !/Time/ && !/Linux/  { if(NR!=2) { if(/^$/){print max;max=0}else if(max<$12){max=$12}  } }'