sort ip.txt | uniq -c | sort -rn | head -n 3
1、首先sort进行排序,将重复的行都排在了一起。
sort ip.txt
2、然后使用uniq -c将重复的行的次数放在了行首。
sort ip.txt | uniq -c
3、再用sort -rn进行反向和纯文本排序,这样就按照重复次数从高到低进行了排列。
sort ip.txt | uniq -c | sort -rn
4、最后利用head -n 3 输出行首的三行。
sort ip.txt | uniq -c | sort -rn | head -n 3