Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

matching more than one line

Status
Not open for further replies.

DJpennywhistle

Programmer
Jun 1, 2000
32
0
0
US
Visit site
I need to match a chunk of data that covers more than 1 line. I've tried using the //m option but I can't get it to work. The data I want to get is in the form:-<br><br>&nbsp;&nbsp;&nbsp;(net (rename bypass &quot;bypass&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(joined<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(portRef bypass)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(portRef IPAD (instanceRef IPAD_bypass))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(portRef I (instanceRef IBUF_bypass))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(portRef O (instanceRef IBUF_bypass))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(portRef D (instanceRef FDC_bypass))<br><br><br>Where bypass is a variable. So I've used the match:-<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(/\(net\s*\(rename\s* $useful/)<br><br>to match the first line where $useful has the value bypass but I need to match the whole damn lot so I can operate on it.<br><br>Actually what I want to do is cut the last two lines and paste them somewhere else but I think I'll be able to work out how to do that myself.<br><br>Thanks <p>Gordon Bell<br><a href=mailto:gordon.bell@xilinx.com>gordon.bell@xilinx.com</a><br><a href= > </a><br>
 
I think you want to use <br><FONT FACE=monospace><br>if(/\(net\s*\(rename\s* $useful<font color=red>.*</font>/<font color=red>s</font>)<br></font><br>'.*' at the end to pick up the remaining lines.<br>The 's' treats the string as a single line, ignoring&nbsp;&nbsp;line feeds and carriage returns.<br><br>This code:<br><FONT FACE=monospace><br>#!/usr/local/bin/perl -w<br>$str = &quot;this is a \nmultiline string\nmultiline string\nmultiline string\n&quot;;<br>print $str;<br>if ($str =~ /multi.*/) { print &quot;\n\nprint w\\o 's' - \n$&\n&quot;; }<br>if ($str =~ /multi.*/s) { print &quot;\n\nprint with 's'- \n$&\n&quot;; }<br></font><br><br>produces this output:<br><FONT FACE=monospace>this is a <br>multiline string<br>multiline string<br>multiline string<br><br><br>print w\o 's' - <br>multiline string<br><br><br>print with 's'- <br>multiline string<br>multiline string<br>multiline string<br></font> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
I forgot to mention that the last line mentioned is not the end of the file - will the .* not give me the whole of the remaining file? <p>Gordon Bell<br><a href=mailto:gordon.bell@xilinx.com>gordon.bell@xilinx.com</a><br><a href= > </a><br>
 
No - actually it doesn't give me the whole of the file - it doesn't actually give&nbsp;&nbsp;me anything different.<br><br>&nbsp;$& = (net (rename bypass &quot;bypass&quot;)<br><br><br>sorry goBoating first time you haven't sorted it for me first time!!!<br><br>Thanks anyway. <p>Gordon Bell<br><a href=mailto:gordon.bell@xilinx.com>gordon.bell@xilinx.com</a><br><a href= > </a><br>
 
so much for batting 1000.&nbsp;&nbsp;<br>How can we identify the end of the string you want to match?&nbsp;&nbsp;<br>Will '<i> (portRef D (instanceRef FDC_bypass))</i>' always be the last line you want to catch?<br><br>If so, this works....<br><FONT FACE=monospace>#!perl -w<br>$buffer = '(net (rename bypass &quot;bypass&quot;)<br> (joined<br> (portRef bypass)<br> (portRef IPAD (instanceRef IPAD_bypass))<br> (portRef I (instanceRef IBUF_bypass))<br> (portRef O (instanceRef IBUF_bypass))<br> (portRef D (instanceRef FDC_bypass))<br>more stuff than I need here.....<br>and more yet.';<br><br>$useful = 'bypass';<br>if($buffer =~ /\(net\s*\(rename\s* $useful.*\(portRef D .*?\)\)/s) <br>&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; print &quot;matched \n$&\n&quot;; <br>&nbsp;&nbsp;&nbsp;&nbsp; }<br></font><br><br>That prints......<br>matched<br>(net (rename bypass &quot;bypass&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(joined<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(portRef bypass)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(portRef IPAD (instanceRef IPAD_bypass))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(portRef I (instanceRef IBUF_bypass))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(portRef O (instanceRef IBUF_bypass))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(portRef D (instanceRef FDC_bypass))<br><br><br>If that is not consistently the last line, we will need to find some method of describing the end of what you want to keep.<br><br>'hope this helps. <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top