举个例子有下面一个文件 1.txt
aaaa,哈哈,9
bbb,啦啦,5
ccc,嗯嗯,6
aaaa,哈哈,6
bbb,啦啦,7
ccc,嗯嗯,4
aaaa,哈哈,3
asd,啦啦,3
###求和
cat 1.txt |awk -F"," '{sum[$2]+=$3}END{for(c in sum){print c,sum[c]}}'
###求平均值
cat 1.txt |awk -F"," '{sum[$2]+=$3;a[$2]++}END{for(c in sum){printf("%s %10d\n", c,sum[c]/a[c])}}'
###根据第二列求每一类的最大值
这个需要写个脚本
#!/bin/bash
type=(`cat 1.txt|awk -F"," '{print $2}'|sort -u`)
for i in `echo ${type[*]}`
do
cat ${log_file}|grep $i|sort -t, -k2 -nk3|tail -n1
done