##统计Apache访问量前3名的IP,并打印出来
##日期:2016-10-12
##作者:Jack Big
#!/bin/bash
logfile='/var/log/apache2/access.log.1'
awk '{print $1}' $logfile | sort | uniq -c | sort -t ' ' -n -r | head -n 3
执行结果:
必须要先sort排序然后再uniq -c,否则可能会出现下面的结果
原因是uniq只会对相邻的重复行进行统计,需要先sort排序将所有重复的行归到一起