群里有个人想统计下面各列的最小值和最大值:
Linux 2.6.9-22.ELsmp (remote) 03/10/12
Time: 03:00:01
avg-cpu: %user %nice %sys %iowait %idle
0.02 0.00 0.05 0.08 99.86
Time: 03:00:06
avg-cpu: %user %nice %sys %iowait %idle
0.00 0.00 0.05 0.15 99.80
Time: 03:00:11
avg-cpu: %user %nice %sys %iowait %idle
0.00 0.00 0.05 0.35 99.60
Time: 03:00:16
avg-cpu: %user %nice %sys %iowait %idle
0.00 0.00 0.05 0.10 99.85
Time: 03:00:21
avg-cpu: %user %nice %sys %iowait %idle
0.00 0.00 0.10 0.20 99.70
。。。。。。。。。。。。。。。。。。。。。
用AWK可以比较简单的实现:
statistics.awk
- awk -F " " 'BEGIN{usermin=100; \
- usermax=0.00; \
- nicemin=100; \
- nicemax=0.00; \
- sysmin=100; \
- sysmax=0.00; \
- iowaitmin=100; \
- iowaitmax=0.00; \
- idlemin=100; \
- idlemax=0.00
- }
- NF==5{ if($1>usermax)usermax=$1; \
- if($1
- if($2>nicemax)nicemax=$2; \
- if($2
- if($3>sysmax)sysmax=$3; \
- if($3
- if($4>iowaitmax)iowaitmax=$4; \
- if($4
- if($5>idlemax)idlemax=$5; \
- if($5
- }
- END{print "User min: ",usermin;
- print "User max: ",usermax;
- print "nice min: ",nicemin;
- print "nice max: ",nicemax;
- print "sys min: ",sysmin;
- print "sys max: ",sysmax;
- print "iowait min: ",iowaitmin;
- print "iowait max: ",iowaitmax;
- print "idle min: ",idlemin;
- print "idle max: ",idlemax;
- }' $1
用法:./statistics.awk filename
结果:
[root@SKCServer-RHEL6 Documents]# ./statistics.awk remoteiostatc.log
User min: 0.00
User max: 1.25
nice min: 0.00
nice max: 0
sys min: 0.00
sys max: 17.16
iowait min: 0.00
iowait max: 4.45
idle min: 79.50
idle max: 100.00
阅读(1267) | 评论(0) | 转发(0) |