【发布时间】:2018-04-25 13:44:01
【问题描述】:
我有以下问题... 我有一个文件,类似于这个:
2018-04-25: line1
2018-04-25: line2
this is another line
I'm a line
2018-04-25: line3
2018-04-25: line4
如果我运行:grep 'this' test.log,结果将是:
this is another line
但我需要的结果是:
2018-04-25: line2
this is another line
I'm a line
因为“这是另一行”实际上是同一个条目的一部分,唯一的问题是我们在那里有一个断行,我需要我的 grep 来忽略这个断行。
- grep -C 1 'this' test.log
- grep -B 1 'this' test.log
不是一个真正的选择,因为我可能在条目的开头和结尾之间有更多的行/断行。
【问题讨论】: