linux - Grep input from file and sum columns based on search -


i using grep input search string file , awk print out sum of columns based on search result using

grep -f input data.txt |awk '{ sum+=$2} end {print sum}' 

this gives me sum input strings. how sum each input string separately?

sample input

a   b   c 

sample data.txt

a/cell1 5   b/cell1 5   a/cell2 8   c/cell1 10 

no of lines in input ~32 size of data.txt - 5gb

expected results:

a 13   b 5   c 5 

$ awk 'nr==fnr{sum[$0]=0;next} $1 in sum{sum[$1]+=$2} end{for (key in sum) print key, sum[key]}' input data.txt 2 b 1 c 1 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -