我怎样才能让grep打印每条匹配行下面和上面的行?
  可能重复: 
  grep一个文件,但显示几条周边线? 
我必须解析一个非常大的文件,我想使用命令grep(或任何其他工具)。
  我想在每个日志行中搜索单词FAILED ,然后在每个匹配行的上下打印行,以及匹配行。 
例如:
id : 15
Satus : SUCCESS
Message : no problem
id : 15
Satus : FAILED
Message : connection error
我需要打印:
id : 15
Satus : FAILED
Message : connection error
  grep的-A 1选项会给你一行后;  -B 1会给你一行;  和-C 1结合起来,给你前后一行。 
使用-B和-A选项
grep --help
...
-B, --before-context=NUM  print NUM lines of leading context
-A, --after-context=NUM   print NUM lines of trailing context
...
使用-A和-B开关(之前和之后的平均线):
grep -A 1 -B 1 FAILED file.txt
上一篇: How can I make grep print the lines below and above each matching line?
