Is there an option for grep, or some similar program, that will print out a whole paragraph - defined as the section between two blank lines - containing a given word or phrase?
If not, can anyone suggest a simple script that will do this?
The perl one-liner below demonstrates this. Setting the $/ (input record separator) var to the empty string causes perl to read in "lines" a paragraph at a time.
$ cat /tmp/text this is a green this is a red this is another green
$ perl -e'$/=""; while () { print if /green/ }' /tmp/text this is a green this is another green
Try grep -p for this.