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:
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