View Single Post
Old 09-11-2015, 05:46 AM   #2
cmccabe
Senior Member
 
Location: chicago

Join Date: Jul 2012
Posts: 350
Default

I am not sure I understand completely, but if you have a file

Code:
ENSMUSG00000000001:001
ENSMUSG00000000001:002
ENSMUSG00000000001:003
ENSMUSG00000000002:001
ENSMUSG00000000002:002
ENSMUSG00000000002:002

you could use:

Code:
awk -F':' -v OFS='\t' '{sum[$1]+=$2} END{for (key in sum) print key, sum[key]}' file.txt
ENSMUSG00000000001      6
ENSMUSG00000000002      5
Hope this helps.

Last edited by cmccabe; 09-11-2015 at 06:10 AM. Reason: added awk
cmccabe is offline   Reply With Quote