Consider the following toy example:
this is a line this line contains FOO this line is not blank This line also contains FOO Some random text This line contains FOO too Not blank Also not blank More random text FOO! Yet more random text FOO!
So, I want the results of a grep for FOO, but with the extra wrinkle that lines following the matching lines should be included, as long as they are not blank, and they do not themselves contain FOO. So the matches would look as follows, with the different matches separated:
this line contains FOO this line is not blank
This line also contains FOO
This line contains FOO too Not blank Also not blank
FOO! Yet more random text
Bonus points (metaphorically speaking) for a simple single line script that can be run on the command line.
ADDENDUM: Adding a running count of the match number would be quite handy, if it is not too hard.