Sum duplicate row values with awk

后端 未结 5 624
故里飘歌
故里飘歌 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:55

    Say you have a top ten lines from many log files output concatened in one file (and sorted with 'sort') with that kind of results :

       2142 /pathtofile1/00.jpg
       2173 /pathtofile1/00.jpg
       2100 /pathtofile1/00.jpg
       2127 /pathtofile1/00.jpg
    

    you can also change the order of sum:

    $ awk '{ seen[$2] += $1 } END { for (i in seen) print i, seen[i] }' top10s.txt | sort -k 2 -rn
    

    and you'll get that total:

    /pathtofile1/00.jpg 8542
    

提交回复
热议问题