需要一些帮助来返回2个特定定界符内的日志文件中的所有数据。我们通常有以下日志:2018-04-17 03:59:29,243 TRACE [xml] This is just a test.2018-04-17 13:22:24,230 INFO [properties] I believe this is another test.2018-04-18 03:48:07,043 ERROR [properties] (Thread-13) UpdateType: more data coming here; ProcessId: 50102018-04-17 13:22:24,230 INFO [log] I need to retrieve this string hereand also this one as it is part of the same text2018-04-17 13:22:24,230 INFO [det] I believe this is another test.如果我将grep设为“ here”,则仅获得包含单词的行,但实际上我需要检索整个文本,则中断可能也导致了我的问题。2018-04-17 13:22:24,230 INFO [log] I need to retrieve this string hereand also this one as it is part of the same text我们可以在日志文件中有几个“这里”。我试图通过sed做到这一点,但是我找不到正确的方法来使用定界符,我认为这应该是整个DATE。
2 回答
摇曳的蔷薇
TA贡献1793条经验 获得超6个赞
与GNUawk多字符记录分隔符
$ awk -v RS='(^|\n)[0-9 :,-]+' '/here/{print rs,$0} {rs=RT}' file
2018-04-18 03:48:07,043 ERROR [properties] (Thread-13) UpdateType: more data coming here; ProcessId: 5010
2018-04-17 13:22:24,230 INFO [log] I need to retrieve this string here
and also this one as it is part of the same text
注意:在这里,我通过创建使用时间戳记中的值的记录分隔符来作弊。您可以精确地制定它,以消除出现在第二行开头的误报。或者,也可以将调试级别添加到匹配项中。
添加回答
举报
0/150
提交
取消