測試文檔test
1 2 3 4 1 2 1 1
sort把相同的放在一起
[root@salt-test ~]# sort test 1 1 1 1 2 2 3 4
uniq -c統計出現的次數
[root@salt-test ~]# sort test |uniq -c 4 1 2 2 1 3 1 4
sort -nr排序 默認按第一列排序
[root@salt-test ~]# sort test |uniq -c|sort -nr 4 1 2 2 1 4 1 3
應用 ,使用此方法可以統計nginx訪問的ip排名類似命令為
awk -F ':' '{print $3}' wwwaccess.log |awk -F "\"" '{print $2}'|sort |uniq -c|sort -nr|head