o/p column wise by nawk

hi
i have file which hav following entries
1501,AAA,2.00
1525,AAA,2.00
1501,AAA,2.00
1525,AAA,2.00
1501,AAA,3.00
1525,AAA,3.00
1525,AAA,3.00
1501,AAA,3.00
1501,AAA,3.00
i want to have a o/p coloum wise
like
1501,AAA,13
1525,AAA,10
here 13 comes as a sum of last colum value corrosponds to 1501
similarly 10 comes as a sum of last colum value corrosponds to 1525

pls help me

Is the second column always AAA and if not, should it go into a separate count for each different value, or sum them all?

awk -F "," '{ sum[$1 "," $2] += $3 } END { for (k in sum) print k "," sum[k] }' file

This will use the values of the first and second fields as the key, and count a sum for each. The output will be in essentially random order.

Thanks era...

if i have a file a.txt
1501,ABB,2.00
1525,AAA,2.00
1501,ACC,2.00
1525,AAA,2.00
1501,AAA,3.00
1525,DDD,3.00
1525,AAA,3.00
1501,AAA,3.00
1501,AAA,3.00

and o/p should be
1501,AAA,9
1525,AAA,7
1501,ABB,2
1501,ACC,2
1525,DDD,3

here is sum with corrsponds to first and second colum both

then is it possible by nawk

That's exactly what's the solution of era is doing. Have you try it?

Regards

hi yes i tried it..
it is working fine but can i do sum if coloum A and B both varies
and also can i find count value

if i have a file a.txt
1501,ABB,2.00
1525,AAA,2.00
1501,ACC,2.00
1525,AAA,2.00
1501,AAA,3.00
1525,DDD,3.00
1525,AAA,3.00
1501,AAA,3.00
1501,AAA,3.00

and o/p should be
data1,data2,sum,count
1501,AAA,9,3
1525,AAA,7,3
1501,ABB,2,1
1501,ACC,2,1
1525,DDD,3,1

pls help me

hi
can any one help me for little bit change in my first prob

i have file which hav following entries
1501,AAA,2.00
1525,AAA,2.00
1501,AAA,2.00
1525,AAA,2.00
1501,AAA,3.00
1525,AAA,3.00
1525,AAA,3.00
1501,AAA,3.00
1501,AAA,3.00
i want to have a o/p coloum wise
like
col1,col2,sum,count
1501,AAA,13 ,5
1525,AAA,10,4
here 13 comes as a sum of last colum value corrosponds to 1501
similarly 10 comes as a sum of last colum value corrosponds to 1525

as per sol given my era
awk -F "," '{ sum[$1 "," $2] += $3 } END { for (k in sum) print k "," sum[k] }' file
it is working fine but if i have to find count too then what need to change in this command

awk -F "," '{ sum[$1 "," $2] += $3; ++cnt[$1 "," $2] }
  END { for (k in sum) print k "," sum[k] "," cnt[k] }' file

You'd do well to google for an introduction to awk so you can learn to make trivial modifications yourself.