Sum duplicate row values with awk

后端 未结 5 629
故里飘歌
故里飘歌 2020-12-11 05:23

I have a file with the following structure:

1486113768 3656
1486113768 6280
1486113769 530912
1486113769 5629824
1486113770 5122176
1486113772 3565920
148611         


        
5条回答
  •  无人及你
    2020-12-11 05:56

    If datamash is okay

    $ datamash -t' ' -g 1 sum 2 < ip.txt 
    1486113768 9936
    1486113769 6160736
    1486113770 5122176
    1486113772 4096832
    1486113773 9229920
    1486113774 8568888
    
    • -t' ' set space as field delimiter
    • -g 1 group by 1st field
    • sum 2 sum 2nd field values
    • if the input file is not sorted, use datamash -st' ' -g 1 sum 2 where the -s option takes care of sorting

提交回复
热议问题