tags:

views:

24

answers:

1

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

Output Format Should be :

9842,5,a1,100000,10
9844,5,a1,100000,10
9845,5,a2,100000,6
9846,1,a2,100000,6
A: 
$ 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
ghostdog74
That's pretty devious; it took me a while to work out what it did. I think it needs some explanation, though.
Jonathan Leffler