https://blog.csdn.net/xiamoyanyulrq/article/details/81570652
首先准备文件demo.txt,内容如下:
1 192.168.41.20
2 192.168.41.21
3 192.168.41.22
4 192.168.41.23
5 192.168.41.24
6 192.168.41.25
统计出现次数最多的ip次数:
cat demo.txt | awk '{print $2}' | sort | uniq -c | sort -n -r | head -n 1
1
注:
awk '{ print $2}':取数据的第2域(第2列),第一列是标号(1,2,3...),第二列是ip地址
sort:对IP部分进行排序。
uniq -c:打印每一重复行出现的次数。(并去掉重复行)
sort -n -r:按照重复行出现的次序倒序排列。
head -n 1:取排在第一位的ip地址