我怎样才能让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's -A 1
选项会给你一行后; -B 1
会给你一行;和 -C 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.
这篇关于我怎样才能让grep打印每条匹配行下面和上面的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文