grep by paragraph

Timothy Murphy gayleard at alice.it
Fri Aug 30 11:03:24 UTC 2013


Dave Mitchell wrote:

>> that will print out a whole paragraph -
>> defined as the section between two blank lines -
>> containing a given word or phrase?
>> 
>> Such as the above 4 lines.
>> 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.

>     $ perl -e'$/=""; while (<>) { print if /green/ }' /tmp/text

Thanks for the solutions.

I gather there is no method using grep or one of its variants?

-- 
Timothy Murphy  
e-mail: gayleard /at/ eircom.net
School of Mathematics, Trinity College, Dublin 2, Ireland




More information about the users mailing list