How can I set the grep after context to be "until the next blank line"?

awk, grep, linux, unix

Solution

It sounds like you need `sed`:

sed -n '/pattern/,/^$/p' file

Don't print by default (`-n`). For lines that match `/pattern/` up to an empty line `/^$/`, print.

Problem

With grep I know how to set the context to a fixed number of lines. Is it possible to show a context based on an arbitrary string condition, like set after-context to "until the next blank line"? Or possibly some other combination of tools? Basically I have a log file of contiguous lines, with blank lines separating the "events" I want to search for a string in the log file, but show the whole event....

Original source