SED解析时间戳之间的Apache日志 [英] SED to parse apache logs between timestamp
本文介绍了SED解析时间戳之间的Apache日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试解析日志并获取时间戳之间的界线.尝试了如下所示的sed方法,但是正则表达式遇到了问题
I am trying to parse a log and get the lines between timestamp.Tried sed approach like below but facing issue with regex
日志模式:
IP - - [20/Apr/2018:14:25:37 +0000] "GET / HTTP/1.1" 301 3936 "-" "
IP - - [20/Apr/2018:14:44:08 +0000]
----------------------------------
IP- - [20/Apr/2018:20:43:46 +0000]
我需要在4月20日获得14:25
和20:43
之间的行,因为日志中还包含其他日期.
I need to get the lines between 14:25
and 20:43
for 20th april as the log contains other dates also.
尝试过:
sed -n '/\[14:25/,/\[20:43/p' *-https_access.log.1
但不起作用.
推荐答案
由于您提到要在4月20日进行日志记录,因此我建议您输入以下内容:
Since you mentioned you want logs for 20th April, I'd suggest something like :
$ sed -n '/20\/Apr\/2018:14:25/,/20\/Apr\/2018:20:43/p' *-https_access.log.1
万一在其他地方出现"20:43",则与假匹配冲突的可能性很小.
This is very less likely to conflict with false matches in case "20:43" occurs elsewhere.
这篇关于SED解析时间戳之间的Apache日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文