Jose Malacara <[EMAIL PROTECTED]> wrote:

> Can someone explain to me how to do multiline matching? I am
> trying to extract three consecutive lines from a datafile
> containing multiple records like this:

Check out 

    perldoc perlre

What you should do is look at the 'm' (multiple line) option.


HTH

JW

 
> Name: Bob
> City: Austin
> State: Texas
> Address: 123 Whatever
> Age: 46 
> 
> Name: Jose
> City: Denver
> State: Colorado
> Address: 118 Mystreet
> Age: 28 
> 
> 
> 
> This is what I have so far, but it doesn't seem to work:
> 
> #!/usr/bin/perl -w
> open FILE, "<file1" or die "Can't open file!\n";
> while (<FILE>){
>   if ( /^Name: (.*)\nCity: (.*)\nState: (.*)/) {
>    print "Match found!\n";  # ideally, I want to print the the
> lines found
>   }
> }
> close FILE;
> 
> But for some reason, it doesn't seem to like the (\n)'s in the
> regex. Any help would be appreciated!
> 
> This is what I would like to return:
> 
> Name: Bob
> City: Austin
> State: Texas
> 
> Name: Jose
> City: Denver
> State: Colorado
> 
> 
> Thanks in advance,
> Jose


__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to