[pid: 28785|app: 0|req: 2291/4303] 192.168.115.161 () {38 vars in 1198 bytes} [Sun Aug 26 12:43:42 2018] GET /v1/posts/ => generated 62220 bytes in 1744 msecs (HTTP/1.1 200) 9 headers in 380 bytes (1 switches on core 3)
我正在使用'grep'搜索日志。
grep '[6-9]{4,} msecs' /var/log/wsgi/wsgi.log
请帮助我过滤所有响应时间超过6秒的日志。
谢谢
答案 0 :(得分:2)
请勿尝试使用正则表达式进行数值比较,而应使用能够理解数字的工具,例如w如果还不够,那么您需要:
awk '$24>6000' file
例如:
$ cat file
[pid: 28785|app: 0|req: 2291/4303] 192.168.115.161 () {38 vars in 1198 bytes} [Sun Aug 26 12:43:42 2018] GET /v1/posts/ => generated 62220 bytes in 1744 msecs (HTTP/1.1 200) 9 headers in 380 bytes (1 switches on core 3)
[pid: 28785|app: 0|req: 2291/4303] 192.168.115.161 () {38 vars in 1198 bytes} [Sun Aug 26 12:43:42 2018] GET /v1/posts/ => generated 62220 bytes in 5744 msecs (HTTP/1.1 200) 9 headers in 380 bytes (1 switches on core 3)
[pid: 28785|app: 0|req: 2291/4303] 192.168.115.161 () {38 vars in 1198 bytes} [Sun Aug 26 12:43:42 2018] GET /v1/posts/ => generated 62220 bytes in 6744 msecs (HTTP/1.1 200) 9 headers in 380 bytes (1 switches on core 3)
$ awk '$24>6000' file
[pid: 28785|app: 0|req: 2291/4303] 192.168.115.161 () {38 vars in 1198 bytes} [Sun Aug 26 12:43:42 2018] GET /v1/posts/ => generated 62220 bytes in 6744 msecs (HTTP/1.1 200) 9 headers in 380 bytes (1 switches on core 3)
然后编辑您的问题,为Minimal, Complete, and Verifiable example提供简洁,可测试的示例输入和预期输出。