【发布时间】:2021-02-21 08:57:14
【问题描述】:
我正在尝试找到一种方法来从一堆类似文件中提取特定文本。示例:
-
Blah1: stuff
Blah2: stuff
Blah3:
- bingo
- this
- is
- what im looking for
Blah4: stuff
-
Blah1: stuff
Blah2: stuff
Blah3:
- bingo this is
- what im looking for
Blah4: stuff
但是,“我正在寻找的宾果游戏”并不总是 4 行,有时是 2 或 15 行遵循相同的模式,但总是以新行开头并以 - 开头,而 Blah3 始终是 Blah3
我需要一种方法来获得仅显示的输出
Blah3:
- Bingo
- this
- is
- what im looking for
Blah3:
- bingo this is
- what im looking for
尝试在 grep 上使用 -A,但 Blah3: 之后出现的行数不一致,并尝试在 grep 中使用相当多的正则表达式,但仍然无法获得我正在寻找的输出
【问题讨论】:
-
我们鼓励提问者展示他们迄今为止为自己解决问题所做的尝试。
-
输入看起来像 yaml。我会在上面尝试 python。