我做了cat results.txt | grep eval
而我得到了
eval: -2.72907
baseline eval (random): -0.031584202184
eval: 0.807805
baseline eval (random): 0.0227601966463
eval: 2.0625
baseline eval (random): 0.0138953249621
如何使用命令行中的linux命令分别对eval
和baseline eval
进行求和?
答案 0 :(得分:6)
Awk可以做到
% grep eval results.txt | awk -F: '{a[$1]+=$2}END{for(i in a)print i ": " a[i]}'
eval: 0.141235
baseline eval (random): 0.00507132
更好的是,正如Johnsyweb在评论中提到的那样,让awk也进行搜索:
awk -F: '/eval/{a[$1]+=$2}END{for(i in a)print i ": " a[i]}' results.txt