grep,awk,sed 命令详解
上一篇对 grep,awk,sed 命令的基本参数做了介绍, 这一篇写一些例子.
1. 分析 access.log 日志内, 当天访问次数最多的 10 个页面, 并且按降序排列.
# cat access.log|awk -F '''{print $7}'|sort|uniq -c|sort -nr|head -10
2. 获取访问最高的 10 个 IP 地址.
# cat access.log|awk -F '''{print $1}'|sort|uniq -c|sort -nr|head -10
3. 查看某个时间段的 access.log 日志 (如: 12 月 8 日 11:00 到 11:50)
# sed -n '/08\/Dec\/2018\:11\:00/,/08\/Dec\/2018\:11\:50/p' access.log
#grep -E '08/Dec/2018:11|08/Dec/2018:11' access.log
5. 查看历史命令使用最多的前 10 个
- # cat /root/.bash_history |awk '{print $1}'|sort|uniq -c|sort -nr|head
- # cat /root/.bash_history|awk '{list[$1]++;} END{for(i in list) {print ("%s\t%d\n",i,list[i]);}}'|sort -nrk 2|head
来源: http://www.bubuko.com/infodetail-2876862.html