Bash – remove 2 lines from output, grep match regular expression plus next 1

bashgrep

i have a log file from postgresql that has log entries of the format;

LOG:  execute <unnamed>: /match this here/
DETAIL:  parameters: /also want to filter this line/

I thought it might be possible with

grep -v --after-context=1 'match this here' /my/log/file.log

but it doesn't work. is there some sed/awk/grep magic, or do i have to do some perl?

Best Answer

As far as I know you cannot do this with grep alone.
awk can do it pretty simple:

awk -v skip=-1 '/match this here/ { skip = 1 } skip-- >= 0 {next } 1' /my/log/file.log

edit:
I assumed that you cannot match the second line by any regex and you really want to match line containing X and the line afterwards. If you can match against a string, it's a lot easier:

egrep -v "match this here|also want to filter this line" /my/log/file.log