[svlug] $GREP question

Bill Ward bill at wards.net
Sun Feb 13 20:33:37 PST 2011

Perl can handle this really nicely by setting the $/ variable to your
delimiter.  Set it to undef to have it split on blank lines, or set it to
your =end delimiter (assuming all content is delimited by begin/end, and
there isn't any content between end and begin that you want to ignore or

You can set $/ using the -0 command line switch; -00 is equivalent to
setting $/ to undef.  So you can do it with these commands:

perl -n -00 -e 'print if /pattern/'
perl -n -0=end -e 'print if /pattern/'

On Sun, Feb 13, 2011 at 4:44 PM, Eric De Mund <ead-svlug at ixian.com> wrote:

> All,
> [$GREP question]
> Hello. How can I $GREP (generically search) a document for a pattern
> and return the records in which it appears, where "record" means either:
> 1.  content delimited by blank lines (perlpod's "paragraph" definition)
>    or:
> 2.  content within some specified "begin" and "end" lines, e.g.
>    =begin record
>    "The trouble ain't that there is too many fools, but that the
>    lightning ain't distributed right."
>    --Mark Twain
>    =end record
> My problem is that I have (and want to have) text files that contain
> both kinds of "records", and I want to be able to search them. Outside
> of begin-end pairs, I want the blank-line definition to hold, and inside
> the begin-end pairs, well, I want the begin-end definition to hold.
> Is this a solved problem? Manber and Wu's agrep(1) comes close, but an
> agrep(1) delimiter must be a fixed string and not a regular expression.
> [meta-question]
> What other forums are good ones for this kind of question?
> Thank you!
> Eric
> --
> Eric De Mund   |  Y!: ead0002
> ead at ixian.com  |  ICQ: 811788
> _______________________________________________
> svlug mailing list
> svlug at lists.svlug.org
> http://lists.svlug.org/lists/listinfo/svlug

Check out my LEGO blog at http://www.brickpile.com/
View my photos at http://flickr.com/photos/billward/
Follow me at http://twitter.com/williamward
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.svlug.org/archives/svlug/attachments/20110213/e3bb56ef/attachment.htm

More information about the svlug mailing list