Raw Input Desired Output
Paragraph-1
not this one
not this one

Paragraph-2
HERE
this one!!

Paragraph-3
this one!!
HERE

Paragraph-4
not this one

Paragraph-5
this one!!
HERE
Paragraph-2
HERE
this one!!

Paragraph-3
this one!!
HERE

Paragraph-5
this one!!
HERE
Script and Comments
Script1
[ 1] /./!d
[ 2] :loop
[ 3] $!{
[ 4] N
[ 5] /\n$/!b loop
[ 6] }
[ 7] /HERE/!d
Comments
  1. To get the paragraphs contains 'HERE',
    • We keep all the lines of a paragraph in the pattern space.
    • When the end of the paragraph reached, if it contains 'HERE', print it out; otherwise just delete it.
  2. The end of a paragraph is reached if
    • the last line of datafile is reached, or
    • the newly appended line is a blank one.
  3. Flowchart: