I have many files with results of command: uniq -c some_file > some_file.out
For example: 1.out:
1 a 2 b 4 c
2.out
2 b 8 c
I would like to merge these results, so I get:
1 a 4 b 12 c
I thought that sort or uniq could handle it but I don't see any option related to it. Writing some ruby/perl script is one of way to go but I'd like to do it easly with core *nix commands (like mentioned sort and uniq).
Edit: To be clear. I don't have original files and I have to merge *.out files.
Thanks for help!
Try it with awk
:
awk '{ count[$2] += $1 } END { for(elem in count) print count[elem], elem }' 1.out 2.out
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With