- 论坛徽章:
- 145
|
本帖最后由 jason680 于 2016-04-26 11:52 编辑
回复 1# zhaolianghz
http://bbs.chinaunix.net/thread-2309494-1-1.html
$ awk '{a[$1]+=$2;b[$1]+=$3}END{for(n in a)print n,a[n],b[n]}' test3
a 244 158
b 1223 44
c 333 333
d 222 333
$ cat test3
a 200 123 # a[$1]+=$2 => a["a"]+=200 => a["a"]=200, b["a"]=123
a 12 32 # a["a"]=212 (200+12), b["a"]=155 (123+32)
a 32 3 # a["a"]=245 (212+32), b["a"]=158 (155+3)
b 1200 aaa # a["b"]=1200, b["b"]=0 (aaa convert to number 0)
b 1 22 # ....
b 22 22
c 333 333 # a["c"]=333, b["c"]=333
d 222 333 # a["d"]=222, b["d"]=333
|
|