merging line and adding number

I having file below o/p

ibapp311dg,,20480,s,,,,,,,,,
test,,20480,s,,,,,,,,,
test,,20480,s,,,,,,,,,
ibapp311dg,,20480,s,,,,,,,,,

I want to to chk unique word line in the first field seperated by , as well as addup corressponding the number in field for each unique word like

ibapp311dg 40960
test 40960

please help

Try this...

awk -F, '{arr[$1]= $3 + $3}END {for(i in arr) {print i" "arr}}' yourfile

I'm afraid that won't give the answer. How about adding to arr[$1] - like

arr[$1] = arr[$1] + $3

instead.

Regards,

pen

yea, you are right...that was my bad!!!

thxs in load fixed my prob......

regards
TaD

u guys nevermind if tell me that wat does it mean, this some specfic syntax

arr[$1] = arr[$1] + $3}END

that code creates an array with name arr[$1] with subscript of the first column of ur file. And , = arr[$1] + $3}END , this will add the third column till the end of the line. I hope u got it!!!

Hi!

The END part (actually, END{...}) marks to code that will be executed when all input has been handled. To be exact, END is a special pattern known to awk, matching end-of-file.

pen

thxs again