我有一个文件,我已将其修剪为如下所示:
"Reno","40.00"
"Reno","40.00"
"Reno","80.00"
"Reno","60.00"
"Lakewood","150.00"
"Altamonte Springs","50.25"
"Altamonte Springs","25.00"
"Altamonte Springs","25.00"
"Sandpoint","50.00"
"Lenoir City","987.00"
等等
我想最终得到的是每个城市的总金额的总和。那是:
"Reno","220.00"
"Lakewood","150.00"
"Altamonte Springs","100.25"
等等。
公平警告,数据集不一定是连续的——也就是说,一个城市可能在这里出现一次,往下千行一次,最后再出现3次。
我一直在尝试使用以下 awk 脚本:
awk -F "," '{array[$1]+=$2} END { for (i in array) {print i"," array[i]}}' test1.csv > test6.csv
我得到的结果如下所示:
"Matawan",0
"Bay Side",0
"Pataskala",0
"Dorothy",0
"Haymarket",0
"Myrtle Point",0
等等。第二列全为零,没有引号。
我显然错过了一些东西,但我不知道该看什么或在哪里看。我错过了什么?
谢谢。