我如何摆脱“--"将 grep 与上下文行一起使用时的行分隔符? [英] How do I get rid of "--" line separator when using grep with context lines?
本文介绍了我如何摆脱“--"将 grep 与上下文行一起使用时的行分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为 compare.txt
的文本文件,我想在其中提取包含模式 nmse_gain_constant
的每一行后面的单行.以下命令让我关闭:
I have a text file named compare.txt
where I want to extract the single line that follows every line that contains the pattern nmse_gain_constant
. The following command gets me close:
grep -A 1 nmse_gain_constant compare.txt | grep -v nmse_gain_constant
但这包括每行所需文本之间的分隔符 --
行.任何简单的想法如何摆脱 --
行?
But this includes a separator --
line between every line of desired text. Any easy ideas how to get rid of the --
lines?
示例:对于看起来像的输入文件
Example: for an input file that looks like
line
line
nmse_gain_constant matching line
line after first match
line
line
nmse_gain_constant another matching line
line after second match
line
nmse_gain_constant a third matching line
line after third match
输出是
line after first match
--
line after second match
--
line after third match
但我只想拥有
line after first match
line after second match
line after third match
推荐答案
我这样做:
grep ... | grep -v -- "^--$"
但这也适用(在许多操作系统上,并非在所有操作系统上)!
But this works too (on many, not all OS'es)!
grep --no-group-separator ...
它不会吐出--"甚至是一个空行.
And it doesn't spit out that "--" or even a blank line.
这篇关于我如何摆脱“--"将 grep 与上下文行一起使用时的行分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文