开发者

Find Out Sum & Also Print All Lines

Input File:

9842,5,a1,100000
9844,5,a1,100000
9845,5,a2,100000
9846,1,a2,100000

Note :

  1. Sum of Column No.2 with respect to Column No.3
  2. Column No.5 will contain sum w.r.t Column +$2=$3

Outp开发者_JAVA百科ut Format Should be :

9842,5,a1,100000,10
9844,5,a1,100000,10
9845,5,a2,100000,6
9846,1,a2,100000,6


$ awk -F"," 'FNR==NR{a[$3]+=$2;next}{print $0,a[$3]}' OFS="," file file
9842,5,a1,100000,10
9844,5,a1,100000,10
9845,5,a2,100000,6
9846,1,a2,100000,6
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜