grep awk sed 练习题

=====统计出18/Jun/2018的pv量======================================
[root@localhost nginx]# grep '18/Jun/2018:10:18:22' access.log |wc -l
6
=====统计出统计2018年6月18日一天内访问最多的2个IP(ip top10)======
[root@localhost nginx]# grep '18/Jun/2018' /var/log/nginx/access.log |awk -F' ' '{ ips[$1]++ } END{ for( i in ips ) { print ips[i],i}}' |sort -k1 -rn |head -n2
34 192.168.44.1
6 192.168.44.47
=====统计出统计2018年6月18日一天内访问大于30的IP======
grep '18/Jun/2018' /var/log/nginx/access.log |awk -F' ' '{ ips[$1]++ } END{ for( i in ips ) { if(ips[i]>30){print ips[i],i}}}' |sort -k1 -rn |head -n2
34 192.168.44.1

============统计出统计2018年6月18日一天ip对应状态码的出现次数
[root@localhost nginx]# grep '18/Jun/2018' /var/log/nginx/access.log |awk -F' ' '{ ips[$1" "$9]++ } END{ for(i in ips){ print i,ips[i]}}'|sort -k3 -rn
192.168.44.1 304 30
192.168.44.47 200 6
192.168.44.46 200 3
192.168.44.1 200 3
192.168.44.1 404 1
=====统计18/Jun/2018 8:30-9:00,访问状态码是404 $9=="404"========
[root@localhost nginx]# awk '$4 >= "[18/Jun/2018:10:00:00" && $4 <= "[18/Jun/2018:11:00:00" { if($9=="404"){ips[$1" "$9]++} } END{ for (i in ips){ print i,ips[i]} }' access.log |sort -k3 -rn
192.168.44.47 404 2
192.168.44.46 404 2
192.168.44.1 404 1
=======查看nginx模块================================
nginx -V 2>&1 |grep 'stub_s'

你可能感兴趣的:(grep awk sed 练习题)