Hi
cat /tmp/xx.txt
1 4
1 5
1 6
2 1
2 1
2 1
i want to add the values of 2nd column resepect to 1st column values..for 1 in 1st column i need sum of all the values in 2nd column ..pls tell me hw to do it??
Hi
cat /tmp/xx.txt
1 4
1 5
1 6
2 1
2 1
2 1
i want to add the values of 2nd column resepect to 1st column values..for 1 in 1st column i need sum of all the values in 2nd column ..pls tell me hw to do it??
What have you tried so far?
i tried
awk 'BEGIN {sum=0} {sum=sum+$5} END {print sum}'
but it is giving total sum.........
but i need to differentiate.........for 1 ( in 1st column ) i want diff sum and for 2 ( in 1st column) i need diff sum
awk '{a[$1]+=$2}END{for(i in a)print i, a}' file
thanks for your help.......
Now output is :
0 0
1 61
2 767
if i want to print 61 and 767 and 0 by printf...........how i will do it.....
i mean if 0 (1st column) then print the count (which is in 2nd column)
I don't see any 0 in the first column in your file in the first post.
Can you post your input file and the desired output?
cat /tmp/vf.txt
0 0
1 61
2 767
i need to print only 61.......how i will do it........
and
i need to print 0 ......
pls give me a code for this
I'm sorry, but this is really unclear.....
With some assumptions..
awk '{A[$1]+=$2}END{for(i=0;i<=$1;i++){print i,A}}' file