Removing dashes in grep -A

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

2 Answers

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.

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 undocumented --group-separator

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

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like