How do I get rid of “--” line separator when using grep with context lines?

前端 未结 5 2077
我在风中等你
我在风中等你 2020-12-13 05:27

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.

5条回答
  •  情书的邮戳
    2020-12-13 06:28

    Well, the A switch by default will add those characters, so it's no mystery.

    man grep states:

    -A NUM
    
        Places  a  line  containing  a  group  separator  (--)   between
        contiguous  groups  of  matches.  With the -o or --only-matching
        option, this has no effect and a warning is given.
    

    But you can use a simple sed to clean up the result:

    yourgrep | sed '/^--$/d'
    

提交回复
热议问题