利用shell脚本统计文件中出现次数最多的IP

时间:2020-12-18 02:35:31

比如有如下文件test.txt

1  134.102.173.43

2  134.102.173.43

3  134.102.171.42

4  134.102.170.9

要统计出现次数最多的IP可以利用以下shell脚本:

cat test.txt | awk '{print $2}' | sort | uniq -c | sort -n -r | head -n 1