4.22. How do I locate a paragraph of text if the paragraph contains a certain regular expression?
Assume that paragraphs are separated by blank lines. For regexes
that are single terms, use one of the following scripts:
sed -e '/./{H;$!d;}' -e 'x;/regex/!d' # most seds
sed '/./{H;$!d;};x;/regex/!d' # GNU sed
To print paragraphs only if they contain 3 specific regular
expressions (RE1, RE2, and RE3), in any order in the paragraph:
sed -e '/./{H;$!d;}' -e 'x;/RE1/!d;/RE2/!d;/RE3/!d'
With this solution and the preceding one, if the paragraphs are
excessively long (more than 4k in length), you may overflow sed's
internal buffers. If using HHsed, you must add a "G;" command
immediately after the "x;" in the scripts above to defeat a bug
in HHsed (see section 7.9(5), below, for a description).