【发布时间】:2021-12-06 06:12:45
【问题描述】:
我想使用 grep 和正则表达式来匹配一行的一部分,然后继续打印该行和接下来的 2 行。但我不想打印第二行匹配后包含另一个正则表达式模式的任何匹配。
示例文本:
If the line was there is a loom in the gloom
would you want that line printed?
Just trying to understand if you're just
other than as part of gloom
if you really do want to exclude lines
even when loom appears on it's own elsewhere on the line
寻找模式,忧郁;使用grep -Pn -A2 '^.*\b(gloom)\b.*$' * 将打印
If the line was there is a loom in the gloom
would you want that line printed?
Just trying to understand if you're just
..和
other than as part of gloom
if you really do want to exclude lines
even when loom appears on it's own elsewhere on the line
但我不想在 第二个 group 上打印包含单词 elsewhere它的第三行。 使用 Perl 正则表达式。
【问题讨论】: