8

I am using grep -A command to get a specific pattern. It gives -- at the end of every block, how I can remove these dashes?

1
  • I suggest you post the problem you are trying to solve, as there might be better ways to accomplish your actual goal.
    – simlev
    Commented May 15, 2019 at 9:47

2 Answers 2

8

AFAIK it's not mentioned in the man page, but in the Context Line Control section of info grep you will find the option

‘--no-group-separator’
     When ‘-A’, ‘-B’ or ‘-C’ are in use, do not print a separator
     between groups of lines.
4

You have at least three alternatives:

  1. With -v option (works on any version of grep):

    ... | grep -A1 "pattern" | grep -v -- "^--$"
    

    Also, | sed '/^--$/d'.

  2. With the undocumented --group-separator

    ... | grep -A1 "pattern" --group-separator "" 
    
  3. With --no-group-separator (as mentioned steeldriver).

    ... | grep -A1 "pattern" --no-group-separator
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .