I want to filter out all lines starting with banana and all lines starting with a space after banana lines. I am using pcregrep. Consider the following file fruits.txt:
apple
banana starts matching
this line should match
this too
and this
mango
pomelo
pcregrep happily finds what I want:
ars@ars-thinkpad ~/tmp/tmp $ pcregrep -M 'banana.*\n(\s.*\n)*' fruits.txt
banana starts matching
this line should match
this too
and this
However, if I try to exclude these lines, pcregrep eats mango too, which is not good:
ars@ars-thinkpad ~/tmp/tmp $ pcregrep -M -v 'banana.*\n(\s.*\n)*' fruits.txt
apple
pomelo
Why?