转自:
http://bbs.chinaunix.net/thread-1842094-1-1.html
$ cat urfile
序号,机构号,金额,姓名,客户号,五级
1,5416,350000,熊清喜,48260000140870,次级
2,5416,50000,杨小平,48260000142862,次级
3,5416,4500,杨明成,48260000144168,次级
4,5417,7000,蒲猛,48260000144266,次级
5,5418,10000,杨小平,48260000142862,可疑
6,5417,5000,张瑞东,48260000145752,可疑
7,5417,500000,杨明成,48260000144168,可疑
8,5419,200000,张瑞东,48260000145752,损失
9,5417,25000,杨小平,48260000142862,正常
10,5417,15000,蒲猛,48260000144266,正常
$ awk 'BEGIN{FS=OFS=","}NR==FNR{a[$5]+=$3;next}{if(FNR>1)$NF=a[$5]","$NF}1' urfile urfile
序号,机构号,金额,姓名,客户号,五级
1,5416,350000,熊清喜,48260000140870,350000,次级
2,5416,50000,杨小平,48260000142862,85000,次级
3,5416,4500,杨明成,48260000144168,504500,次级
4,5417,7000,蒲猛,48260000144266,22000,次级
5,5418,10000,杨小平,48260000142862,85000,可疑
6,5417,5000,张瑞东,48260000145752,205000,可疑
7,5417,500000,杨明成,48260000144168,504500,可疑
8,5419,200000,张瑞东,48260000145752,205000,损失
9,5417,25000,杨小平,48260000142862,85000,正常
10,5417,15000,蒲猛,48260000144266,22000,正常