Friends,
I have to run iostat -d on my AIX machine and print the sum of the output in tps column per iteration. can any one pls guide me how to do this using awk. here is the sample output
iostat -d 2 2 | awk '!/System/ && !/Disks/ && !/cd[0-9]/ && !/^$/ {print $4}'
2.0
3.0
1.0
3.0
My system contains two hard disks. so output will be
5
4.
can anyone guide me how to do this?
mkastin
October 30, 2009, 11:20am
2
Not the best way to do it, but it'll work....
$ iostat -d 2 2 | awk '{if(NR > 3 && NR < 6) SUM1 += $2; if(NR > 7 && NR < 10) SUM2 += $2 } END { print "iteration 1:" SUM1 " iteration 2:" SUM2 }'
iteration 1:7.43 iteration 2:4.96
or
iostat -d 2 2 | awk '{if(NR > 3 && NR < 6) SUM1 += $2; if(NR > 7 && NR < 10) SUM2 += $2 } END { print SUM1 "\n" SUM2 }'
7.43
4.96
This is simple and won't loop for more iterations.