使用awk进行分类汇总

adam@adam-desktop:~$ cat test.txt
round1    peter    100
round1    adam    20
round1    alice    50
round2    peter    20
round2    adam    50
round2    alice    30
round3    peter    20
round3    mike    50
round3    jack    80

adam@adam-desktop:~$ awk '{scores[$2]+=$3} END {for (i in scores) print i, scores[i]}' test.txt
peter 140
mike 50
jack 80
adam 70
alice 80

Comments are closed.