Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > matching multiple lines as one record

Reply
Thread Tools

matching multiple lines as one record

 
 
Stephen Moon
Guest
Posts: n/a
 
      02-27-2004
I have a file containing the following data. How would you use
regular expression to match the record from the header before the next
header.

G11: AD113167 #beginnning of header

Freq Mag
----------------------------------
0.00000 0.0002430974787725
0.01987 0.0002434897808872
...
G22: AD113168 #start of next header

Freq Mag
----------------------------------
0.09934 0.0000005524295687
0.11921 0.0000005192898866
0.13908 0.0000003088175192
...
G33: AD113169
...

$header =~ s/\A(.*?: \w+\s*)//
$record =~ s/\s*(.*?)\s+(\S+)/$1,$2/
I used the above for the header and the data.
It seems like '.' doesn't match new lines and '^' and '$' only works
for
a string.

Thanks in advance.

-Steve
 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      02-27-2004
In article <(E-Mail Removed) >,
Stephen Moon <(E-Mail Removed)> wrote:
:I have a file containing the following data. How would you use
:regular expression to match the record from the header before the next
:header.

Please see the 's' and 'm' modifiers of the 's' operator.
--
Feep if you love VT-52's.
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      02-27-2004
Stephen Moon <(E-Mail Removed)> wrote:

> It seems like '.' doesn't match new lines



What's with the "seems like"?

That is what the docs say that dot means.

They also say how to make dot match newlines...


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Brad Baxter
Guest
Posts: n/a
 
      03-03-2004
On Thu, 26 Feb 2004, Stephen Moon wrote:
> I have a file containing the following data. How would you use
> regular expression to match the record from the header before the next
> header.


Your subject says, "multiple lines as one record" but your note says, "I
have a file". Maybe the file answer would simply things.

while ( <DATA> ) {
/([^:]+):\s(\w+)/ and do{ print "Header: $1,$2\n"; next };
/(\d+\.\d+)\s+(\d+\.\d+)/ and do{ print "Record: $1,$2\n"; next };
}

__DATA__
G11: AD113167 #beginnning of header

Freq Mag
----------------------------------
0.00000 0.0002430974787725
0.01987 0.0002434897808872

G22: AD113168 #start of next header

Freq Mag
----------------------------------
0.09934 0.0000005524295687
0.11921 0.0000005192898866
0.13908 0.0000003088175192

G33: AD113169

__END__


Regards,

Brad
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Pattern matching. Matching multiple lines from while reading from a file. Bobby Chamness Perl Misc 2 05-03-2007 06:02 PM
Preserve blank lines when add multiple lines of text to a cell Cah Sableng Javascript 0 04-23-2007 04:46 AM
matching over multiple lines cyborg Perl Misc 4 11-21-2006 10:39 AM
matching HTML expression across multiple lines H.S. Perl Misc 9 05-11-2006 04:12 PM
Matching multiple lines with regexp lcs Mixmaster Remailer Perl Misc 1 02-11-2004 06:46 PM



Advertisments