Hi
I have a file like
2291, 382718.00
2291, 19338.00
2291, 9073.00
2292, 4707.00
2293, 495847.00
2293, 157310.00
2293, 63582.00
2293, 100059.00
2293, 2843.00
2293, 58597.00
2293, 14836.00
2293, 24204.00
I want to sum the second column and place the result beside the last record
whenever the first column value changes.
2291, 382718.00 ,
2291, 19338.00 ,
2291, 9073.00 , 411129.00
2292, 4707.00 , 4707.00
2293, 495847.00 ,
2293, 157310.00 ,
2293, 63582.00 ,
2293, 100059.00 ,
2293, 2843.00 ,
2293, 58597.00 ,
2293, 14836.00 ,
2293, 24204.00 , 917278.00
My program is adding all the second column values and giving the result
at the end. I am not able to break the totals depending on the first column values.
awk '{
a[NR] = $0
sum += $2
}
END {
for (x = 1; x <= NR-1; x++) {
printf"%s\n", a[x]
}
printf"%s %s\n", a[NR],sum
}'
Please help
I have a file like
2291, 382718.00
2291, 19338.00
2291, 9073.00
2292, 4707.00
2293, 495847.00
2293, 157310.00
2293, 63582.00
2293, 100059.00
2293, 2843.00
2293, 58597.00
2293, 14836.00
2293, 24204.00
I want to sum the second column and place the result beside the last record
whenever the first column value changes.
2291, 382718.00 ,
2291, 19338.00 ,
2291, 9073.00 , 411129.00
2292, 4707.00 , 4707.00
2293, 495847.00 ,
2293, 157310.00 ,
2293, 63582.00 ,
2293, 100059.00 ,
2293, 2843.00 ,
2293, 58597.00 ,
2293, 14836.00 ,
2293, 24204.00 , 917278.00
My program is adding all the second column values and giving the result
at the end. I am not able to break the totals depending on the first column values.
awk '{
a[NR] = $0
sum += $2
}
END {
for (x = 1; x <= NR-1; x++) {
printf"%s\n", a[x]
}
printf"%s %s\n", a[NR],sum
}'
Please help