matching multiple lines as one record

S

Stephen Moon

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
 
W

Walter Roberson

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

Tad McClellan

Stephen Moon said:
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...
 
B

Brad Baxter

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top