1. 程式人生 > >截取某個時間段日誌

截取某個時間段日誌

截取日誌

leco@leco:~/PycharmProjects/cmz/練習/7並發編程/多線程$ cat web.log

192.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方式去截取

leco@leco:~/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方式去截取

leco@leco:~/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


截取某個時間段日誌