Help in AWK

Hi friends,

I have a text file as follows

X 20
Y 60
X 40
U 30
X 10
U 20

I want to get an out put like follow

X 70
Y 60
U 50

It should group the name and add the values together..
Please tell me how to do this using awk..

Thanks in advance..

Windi

Try this :
########### sum.awk #################
BEGIN{
FS=" ";
}

{

key=$1;
sum2[key]+=$2;
}

END{ for (word in sum2)
printf("%s %s\n",word,sum2[word]);
}
########### sum.awk #################

Hi friends,

I have a text file as follows

X 20
Y 60
X 40
U 30
X 10
U 20

I want to get an out put like follow

X 70
Y 60
U 50

It should group the name and add the values together..
Please tell me how to do this using awk..

Thanks in advance..

Windi
Edit/Delete Message

something like this may help

awk'
BEGIN{FS=" "}
/X/   { x_count+= $2 }
/Y/   { y_count+= $2 }
/Z/   { z_count+= $2 }
END { 
         printf ("X %d\n",x_count);
	 printf ("Y %d\n",y_count);
	 printf ("Z %d\n",z_count);
}' inputfile
$ awk '{arr[$1]+=$2} END {for (i in arr) {print i,arr}}' win.txt
U 50
X 70
Y 60

Hiii

Thanks a lot..................................
:cool:

windi