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 :
- Sum of Column No.2 with respect to Column No.3
- 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
精彩评论