I have asked similar question here, but this one I feel is more complicated than that so, asking in different post.
foo foo foo foo foo
Import blash blah blah
foo foo foo foo foo
blah blah blah blah
Error loading file
blah blah blah blah
blah blah blah blah
query run ends
foo foo foo foo
Import blash blah blah
foo foo foo foo foo
foo foo foo foo foo
Exception occurred
blah blah blah blah
blah blah blah blah
query run ends
Import blash blah blah
foo foo foo foo foo
foo foo foo foo foo
query run ends
In the pattern similar to above, I want to grep all the contents between all Import and ends if Error or Exception exist in between them. And in that process I want to exclude those Import & ends combination which doesn't have any Error or Exception string.
Note:
The lines between Import & ends strings are not constant, it may vary.
Expected:
Import blash blah blah
foo foo foo foo foo
blah blah blah blah
Error loading file
blah blah blah blah
blah blah blah blah
query run ends
Import blash blah blah
foo foo foo foo foo
foo foo foo foo foo
Exception occurred
blah blah blah blah
blah blah blah blah
query run ends