0

我的输入文件是物品的价格表,在那个特定的物品中,我想计算大米物品的总和和平均值awk

Chenna Black |1|76.00|Chenna
Chenna White big|1|102.00|Chenna
Chenna White small|1|82.00|Chenna
Dhal-Gram|1|78.00|Dhal
Dhal-Moong|1|76.00|Dhal
Dhal-Orid|1|72.00|Dhal
Dhal-Toor|1|68.00|Dhal
Dhal-Green gram|1|88.00|Dhal
Rajma-Black|1|72.00|Rajma
Rajma-Pink|1|80.00|Rajma
Rice-Basmanthi|1|80.00|Rice
Rice-Boiled|1|42.00|Rice
Rice-Idly|1|33.00|Rice
Rice-IGBasamanthi|1|99.00|Rice
Rice-Karanatka Ponni|1|38.00|Rice
Rice-Nirapara Silky|1|235.00|Rice
Rice-Raw|1|40.00|Rice
Rice-Roasted Gram|1|100.00|Rice
4

1 回答 1

1

所有大米项目的总和和平均值使用awk

$ awk -F'|' '$4=="Rice"{s+=$3;c++}END{printf "sum: %.2f avg: %.2f\n",s,s/c}' file
sum: 667.00 avg: 83.38
于 2013-06-20T08:51:25.947 回答