Grep 查找最后一行之外的标记
这看起来应该很容易,但我无法获得正确的语法。我正在尝试使用 grep 查找具有特定标记的所有文件,这些文件在包含该标记的行之后至少有一行。所以
blah blah token blah
another line here
grep 会找到类似的东西,但不会:
blah blah token blah
This seems like it should be easy, but I can't get the right syntax. I'm trying to use grep to find all files with a certain token that have at least one line following the line with the token in it. So something like:
blah blah token blah
another line here
would be found by the grep, but not:
blah blah token blah
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定
grep
不做类似的多行事物(尽管有-a可以打印尾随上下文的选项)。一种方法是首先使用head
切断最后一行,然后将其输送到grep
:上面的代码未测试,我卡在Windows ATM上。
I'm pretty sure
grep
doesn't do multi-line stuff like this (though there is a -A option to print trailing context). One way would be to usehead
to cut off the last line first, then pipe it togrep
:Above code is not tested, I'm stuck on Windows atm.