截取某个时间段日志
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了截取某个时间段日志相关的知识,希望对你有一定的参考价值。
[email protected]:~/PycharmProjects/cmz/练习/7并发编程/多线程$ cat web.log192.168.5.109 - - [01/Apr/1027:21:26:21 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:28:22 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:31:36 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:42:14 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:45:22 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:46:32 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:46:54 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:47:03 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:48:31 +0800] "GET / HTTP/1.1" 200 26 192.168.5.109 - - [01/Apr/1027:21:50:08 +0800] "GET / HTTP/1.1" 200 26 192.168.5.109 - - [01/Apr/1027:21:51:21 +0800] "GET / HTTP/1.1" 200 26 192.168.5.109 - - [01/Apr/1027:21:52:48 +0800] "GET / HTTP/1.1" 200 26
sed方式去截取
[email protected]:~/PycharmProjects/cmz/练习/7并发编程/多线程$ sed -n '/21:31:36/,/21:50:08/p' web.log
192.168.5.109 - - [01/Apr/1027:21:31:36 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:42:14 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:45:22 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:46:32 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:46:54 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:47:03 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027:21:48:31 +0800] "GET / HTTP/1.1" 200 26 192.168.5.109 - - [01/Apr/1027:21:50:08 +0800] "GET / HTTP/1.1" 200 26
awk方式去截取
[email protected]:~/PycharmProjects/cmz/练习/7并发编程/多线程$ awk -F':' '$2 = 21 && $3 >= 30 && $3 <= 50' web.log
192.168.5.109 - - [01/Apr/1027 1 31 36 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027 1 42 14 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027 1 45 22 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027 1 46 32 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027 1 46 54 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027 1 47 03 +0800] "GET / HTTP/1.1" 502 172 192.168.5.109 - - [01/Apr/1027 1 48 31 +0800] "GET / HTTP/1.1" 200 26
以上是关于截取某个时间段日志的主要内容,如果未能解决你的问题,请参考以下文章