工作中常用的若干正则
sed过滤日志中一天的日期
- sed -n '/03\/Nov\/2017/p' www.kanfanews.com_access_ssl.log
grep过滤时间
- cat jie.Nginx.log|grep 117.73.151.80|egrep "21/Oct/2017:10:[0-9][0-9]:[0-9][0-9]"
sed过滤日志中连续字符中的空格
- sed -n '/28\/Oct\/2017/p' www.kanfanews.com_access_ssl.log_ngx232_20171029 | egrep '"GET\s/web/video/index/994053/'过滤GET空格/web/video
查看日中中排名前十的ip
- awk '{print $1}' GET_1002131_2017_11_01_Nginx.log | sort |uniq -c| sort -k 1 -r -n| head -n 15
61 117.136.0.22
32 123.151.77.72
30 39.155.214.66
25 123.151.76.158
24 223.104.13.196
23 123.151.77.71
23 123.151.77.70
22 123.151.77.123
22 120.52.147.18
20 123.151.76.248
19 123.151.77.132
19 111.30.142.78
17 123.151.77.91
17 113.96.218.50
16 111.30.142.252
sed 删除特殊字符
- sed 's/\[//g' file 删除[ 这里的\ 是用来表达转义
awk删除某列
- tail -2 test.log |awk '{$(NF-4)=null;$(NF-5)=null;$1=null;print}'nf-4 列为空,其他同理,然后print 打印
egerp过滤多个条件