awk 分类取最大值,平均值
时间:2010-07-27 来源:wood016
awk 分类取最大值
FILE内容如下:
===============
10.130.7.165 55
10.130.7.165 56
10.130.7.165 57
10.130.7.165 58
10.130.7.166 55
10.130.7.166 56
10.130.7.166 57
10.130.7.166 58
10.134.138.140 55
10.134.138.140 56
10.134.138.140 57
10.134.138.140 58
10.134.138.172 55
10.134.138.172 56
10.134.138.172 57
10.134.138.172 58 awk 程序如下: awk 'BEGIN {printf "%s,%5s,%4s\n","IP","AVG","MAX"}{A[$1]++;SNF[$1]+=$NF;MAXNF[$1]=($NF>MAXNF[$1]?$NF:MAXNF[$1])}END{for (IP in A) print IP,SNF[IP]/A[IP],MAXNF[IP]}' FILE 输出结果:
IP, AVG, MAX
10.130.7.165 56.5 58
10.130.7.166 56.5 58
10.134.138.140 56.5 58
10.134.138.172 56.5 58 ===============END
10.130.7.165 56
10.130.7.165 57
10.130.7.165 58
10.130.7.166 55
10.130.7.166 56
10.130.7.166 57
10.130.7.166 58
10.134.138.140 55
10.134.138.140 56
10.134.138.140 57
10.134.138.140 58
10.134.138.172 55
10.134.138.172 56
10.134.138.172 57
10.134.138.172 58 awk 程序如下: awk 'BEGIN {printf "%s,%5s,%4s\n","IP","AVG","MAX"}{A[$1]++;SNF[$1]+=$NF;MAXNF[$1]=($NF>MAXNF[$1]?$NF:MAXNF[$1])}END{for (IP in A) print IP,SNF[IP]/A[IP],MAXNF[IP]}' FILE 输出结果:
IP, AVG, MAX
10.130.7.165 56.5 58
10.130.7.166 56.5 58
10.134.138.140 56.5 58
10.134.138.172 56.5 58 ===============END
相关阅读 更多 +