Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在返回显着误报的搜索中使用 grep,并且通过检查确定好的结果可能比编写更复杂的 grep 表达式更容易。
为此,我需要为每个结果查看超过 1 行。
我可以(我如何)指示 grep 在每场比赛的上方和下方返回 1-2 行吗?
如果你有GNU grep,那么:
grep
grep -A 2 -B 2orgrep -C 2 -A代表 after -B代表 before -C代表上下文(之前和之后)
grep -A 2 -B 2
grep -C 2
-A
-B
-C
来源和更多选项:http ://unixhelp.ed.ac.uk/CGI/man-cgi?grep