1

我做一个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

4

1 回答 1

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 -F: '/eval/{a[$1]+=$2}END{for(i in a)print i ": " a[i]}' results.txt
于 2013-05-15T23:01:30.700 回答