假设我有一个文本文件,其中的代码行如下:
foo 10
bar 15
bar 5
foo 30
...生成以下输出的最简单方法是什么:
foo 40
bar 20发布于 2012-11-07 04:38:46
使用以下awk脚本:
awk '{sums[$1] += $2} END {for (a in sums) print a, sums[a]}' infile输出:
foo 40
bar 20Use this awk tutorial on using associative arrays
https://stackoverflow.com/questions/13258902
复制相似问题