I have a large file containing data like this:
a 23 b 8 a 22 b 1
I want to be able to get this:
a 45 b 9
One way using perl:
perl
perl -ane ' next unless @F == 2; $h{ $F[0] } += $F[1]; END { printf qq[%s %d\n], $_, $h{ $_ } for sort keys %h; } ' infile
Content of infile:
infile
Output: