Linux 中按照指定列中的项取平均值
001、
[root@localhost test2]# ls a.txt [root@localhost test2]# cat a.txt ## 测试数据 a 7 a 10 a 9 a 2 b 5 b 12 c 4 c 6 c 3 c 11 d 8 d 1 [root@localhost test2]# awk '{ay1[$1] += $2; ay2[$1]++}END{for(i in ay1) {print i, ay1[i]/ay2[i]}}' a.txt ## 指定第一列中的项求平均值 a 7 b 8.5 c 6 d 4.5

。

浙公网安备 33010602011771号