How to sort,uniq and display line that appear more than X times

后端 未结 2 1748
野性不改
野性不改 2021-02-07 13:02

I have a file like this:

80.13.178.2
80.13.178.2
80.13.178.2
80.13.178.2
80.13.178.1
80.13.178.3
80.13.178.3
80.13.178.3
80.13.178.4
80.13.178.4
80.13.178.7


        
相关标签:
2条回答
  • 2021-02-07 13:17

    With pure awk:

    awk '{a[$0]++}END{for(i in a){if(a[i] > 2){print i}}}' a.txt 
    

    It iterates over the file and counts the occurances of every IP. At the end of the file it outputs every IP which occurs more than 2 times.

    0 讨论(0)
  • 2021-02-07 13:21

    Feed the output from uniq -cd to awk

    sort test.file | uniq -cd | awk -v limit=2 '$1 > limit{print $2}'
    
    0 讨论(0)
提交回复
热议问题