contains a certain regular expression?
Assume that paragraphs are separated by blank lines. For regexes that are single terms, use the following script: sed -e ‘/./{H;$!d;}’ -e ‘x;/regex/!d’ 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 6.7.F(5), below, for a description).