How to use sed to print a paragraph containing one or more regular expressions

 

Print a paragraph if it contains AAA (blank lines separate paragraphs)

HHsed v1.5 must insert a 'G;' after 'x;' in the scripts below

sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;'

 

Print a paragraph if it contains AAA and BBB and CCC (in any order)

sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;/BBB/!d;/CCC/!d'

 

Print a paragraph if it contains AAA or BBB or CCC

sed -e '/./{H;$!d;}' -e 'x;/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d

gsed '/./{H;$!d;};x;/AAA\|BBB\|CCC/b;d' # GNU sed only