开发者

Find Out Sum & Also Print All Lines

开发者 https://www.devze.com 2023-01-18 20:26 出处:网络
Input File: 9842,5,a1,100000 9844,5,a1,100000 9845,5,a2,100000 9846,1,a2,100000 Note : Sum of Column No.2 with respect to Column No.3

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

精彩评论

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