perl - How to sum values in a column grouped by values in the other -


i have large file consisting data in 2 columns

100 5 100 10 100 10 101 2 101 4 102 10 102 2 

i want sum values in 2nd column matching values in column 1. example, output i'm expecting is

100 25 101 6 102 12 

i'm trying work on using bash script preferably. can explain me how can this

using awk:

awk '{a[$1]+=$2}end{for(i in a){print i, a[i]}}' inputfile 

for input, it'd produce:

100 25 101 6 102 12 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -