1

So in a file i have lines like these:

thisdata:thisother:1337
thisdata:thisother:1800
thisdata:thisother:1500
thisdata:thisother:46984

I would like to output:

thisdata:thisother:51621

for all lines, differenciating amount of lines per dataset with alternating numbers on the end that I'd like to merge.

More examples:

somedata:somedata:1339

othrsome:othersomemore:14949
othrsome:othersomemore:14949

uruie:eiiwi:1399
uruie:eiiwi:1399
uruie:eiiwi:1399
3

Using awk and an associative array keyed on the first two columns:

awk -F : '{ sum[$1 FS $2] += $3; }; END { OFS=FS; for (key in sum) print key, sum[key]; }' file
  • Brilliant again! – jano Jun 22 '15 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.