我如何摆脱“ - ”使用grep和上下文行时的行分隔符? [英] How do I get rid of "--" line separator when using grep with context lines?
问题描述
我有一个名为compare.txt的文本文件,我想提取包含模式nmse_gain_constant的每一行后面的单行。以下命令让我关闭:
I have a text file named compare.txt that 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?
我会给你一些示例文本,但 - 字符被错误地解释作为控制字符,你会看到什么是不正确的。
I'd give you some example text here, but the "--" characters get erroneously interpreted by this web post as control characters and what you would see is not correct.
推荐答案
我这样做:
grep ... | grep -v -- "^--$"
但是这也适用!
grep --no-group-separator ...
它不会吐出那个 - 或甚至是一个空行。
And it doesn't spit out that "--" or even a blank line.
这篇关于我如何摆脱“ - ”使用grep和上下文行时的行分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!