shell统计访问日志的IP并排序(很笨的方法)

1.grep “[1-9]{1,3}.[1-9]{1,3}.[1-9]{1,3}.[1-9]{1,3}” nginx.access.log | awk ‘{ print $1 }’ | sort | uniq -c | sort -r | head -n 2
2.只针对nginx的log格式为$remote_addr – $remote_user [$time_local] “$request“ $status $body_bytes_sent “$http_referer””$http_user_agent” “$http_x_forwarded_for”的排序
cut -d -f 1 nginx.access.log | awk ‘{ print $1 }’ | sort | uniq -c | sort -r | head -n 2
不过如果是这样可以修改-d 和-f 去工作

留下评论