打印匹配行之后的所有行
如何打印第 n 行中匹配模式后的所有行,但忽略匹配行之前的所有行(包括匹配行),这里是一个示例:
row1 something in this row
row2 something in this row
row3 something in this row
row4 don't need to match the whole line, something like java String.contains()
row5 something in this row
row6 something in this row
row7 something in this row
row8 something in this row
row9 something in this row
row10 something in this row
我希望打印包含该行中任意位置的 row4 的行后面的行,这可能吗用 awk 或 sed 或任何其他方式?
输出应该是:
row5 something in this row
row6 something in this row
row7 something in this row
row8 something in this row
row9 something in this row
row10 something in this row
我见过类似的问题:
但我不知道如何调整它来满足我的需要。
How can I print all rows after matching pattern in nth row, but ignore all before matched row including the matching row, here is an example :
row1 something in this row
row2 something in this row
row3 something in this row
row4 don't need to match the whole line, something like java String.contains()
row5 something in this row
row6 something in this row
row7 something in this row
row8 something in this row
row9 something in this row
row10 something in this row
I'm looking to print lines following the line which contains row4 anywhere in that row, is this possible with awk or sed, or any other way?
Output should be :
row5 something in this row
row6 something in this row
row7 something in this row
row8 something in this row
row9 something in this row
row10 something in this row
I've seen similar question :
Awk - print next record following matched record
But I'm not sure how to adapt it to fit my needs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
试试这个:
Try this:
如果 Perl 没问题,你可以这样做:
代码实际操作
If Perl is fine with you can do:
Code in Action
您可以使用以下命令:
输出将为:
-A
表示“之后”,类似地,您可以使用-B
键表示“之前”。5
是要输出的行数。当然你可以选择任何你想要的。You an use the following command:
The output will be:
-A
goes for After and similary you can use-B
key which goes for Before.5
is the number of lines to output. You can choose whatever you want of course.这是可行的,专家可能可以大大缩短它:
从命令行:
This works, a guru could probably shorten it considerably:
From the cmdline: