我需要解析一个文件,我希望在两个特定行之间打印一段数据。从“范围开始”到“范围结束”,但前提是“范围结束”存在。
如果源文件是:
[This is the start] of some data
this is information
this is more information
This is does not contain the ending required
[This is the start] of some other data
this is info I want
this is info I want
[This is the ending I was looking for]
Run Code Online (Sandbox Code Playgroud)
它应该打印:
[This is the start] of some other data
this is info I want
this is info I want
[This is the ending I was looking for]
Run Code Online (Sandbox Code Playgroud)
使用 grep 我已经能够找到我需要的数据并向上打印,但只能通过固定数量的行。 …