Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

There was a post here a while ago that did just what I wanted but after looking and looking I couldn't find it.

I have a records text file which looks like

Name: name Phone: number Fax: number Address: address Email: email address Info: information %%%
And I want to search to and find all the chunks of code that have let's say "644-451" in it. Each entry is separated with three %'s. How much more difficult would it be that instead of searching everything for a string that I could search just the email field to see if that contains a specific address?

There was a node just like this a month or two ago, anyone remember what it was called?

Replies are listed 'Best First'.
Re: Searching log file by %%%
by jmcnamara (Monsignor) on May 18, 2004 at 21:18 UTC

    You can read the records one at a time by setting the input record separator $/ to %%%. See $/ in perlvar:
    #!/usr/bin/perl -wl $/ = "%%%"; while (<DATA>) { chomp; print if /Email/; # Change to suit } __DATA__ Name: name Phone: number Fax: number Address: address Email: email address Info: information %%% Name: name Phone: number Fax: number Address: address Email: email address Info: information

    --
    John.

      Thank you for that, that helps a lot. Can you help me figure out how to search just a specific chunk of this? Instead of matching /Email/ anywhere in there, say we just want to match it in one place. A better example would be "brown cow". I just want to find this following Info: , if it follows Email or Address or anything else, it ignores it. Is there any easy way to do this simply?
        Do a regex of substr-search for Info: brown cow.

        Email: brown cow or others will not match.

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Searching log file by %%%
by CountZero (Bishop) on May 18, 2004 at 21:14 UTC
    A weird thought: set "Email:" to be your record separator and check for the beginning of each such record for 644-451.

    Or use a database, of course ;-)

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Searching log file by %%%
by Anonymous Monk on May 18, 2004 at 20:47 UTC
    Well you could just search the chunks where only every entry is 644-451 and just get the email address strings.