如何让 grep 打印每个匹配行下方和上方的行? [英] How can I make grep print the lines below and above each matching line?
本文介绍了如何让 grep 打印每个匹配行下方和上方的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须解析一个非常大的文件,我想使用命令 grep(或任何其他工具).
I have to parse a very large file and I want to use the command grep (or any other tool).
我想在每个日志行中搜索词 FAILED
,然后在每个匹配行的上方和下方打印该行,以及匹配的行.
I want to search each log line for the word FAILED
, then print the line above and below each matching line, as well as the matching line.
id : 15
Satus : SUCCESS
Message : no problem
<小时>
id : 15
Satus : FAILED
Message : connection error
<小时>
我需要打印:
And I need to print:
id : 15
Satus : FAILED
Message : connection error
推荐答案
grep 的 -A 1
选项会给你一行;-B 1
会给你前一行;和 -C 1
将两者结合起来,在前后给你一行,-1
做同样的事情.
grep's -A 1
option will give you one line after; -B 1
will give you one line before; and -C 1
combines both to give you one line both before and after, -1
does the same.
这篇关于如何让 grep 打印每个匹配行下方和上方的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文