grep要查找字符串,请获取前后的行,不显示行号
最近,我需要在文件中搜索一个特定的字符串,我需要在匹配之前和之后显示该行 文件 哪些输出grep要查找字符串,请获取前后的行,不显示行号,grep,Grep,最近,我需要在文件中搜索一个特定的字符串,我需要在匹配之前和之后显示该行 文件 哪些输出 1-AAAA 2-BBBB 3-CCCC 这就是我想要的,除了在输出中显示行号 有没有办法抑制行号?只需删除n grep-1 BBBB输入 同时使用sed sed-n'n;N/\n、 *BBBB.*\n/p'输入 使用以下方法: grep -C 1 BBBB input grep有三个显示上下文行的选项: 很好!谢谢,你可能发现我是新来的:-)太酷了!这样,我可以得到X行数之前,之后或两者!那会派上用
1-AAAA
2-BBBB
3-CCCC
这就是我想要的,除了在输出中显示行号
有没有办法抑制行号?只需删除
n
grep-1 BBBB输入
同时使用sed
sed-n'n;N/\n、 *BBBB.*\n/p'输入
使用以下方法:
grep -C 1 BBBB input
grep
有三个显示上下文行的选项:
很好!谢谢,你可能发现我是新来的:-)太酷了!这样,我可以得到X行数之前,之后或两者!那会派上用场的,谢谢!
1-AAAA
2-BBBB
3-CCCC
grep -C 1 BBBB input
-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching lines. Places a line containing -- between contiguous groups of
matches.
-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines. Places a line containing -- between contiguous groups of
matches.
-C NUM, --context=NUM
Print NUM lines of output context. Places a line containing -- between contiguous groups of matches.