Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Getting lines in a file between two patterns

by johngg (Canon)
on Jul 05, 2012 at 09:45 UTC ( [id://980002]=note: print w/replies, xml ) Need Help??


in reply to Getting lines in a file between two patterns

Another solution, if the printing of "START" and "END" is not desired, would be to keep flipping the value of $/.

$ perl -Mstrict -Mwarnings -E ' > open my $inFH, q{<}, \ <<EOD or die $!; > ssdfif > START > Line 1 > Line 2 > END > iufifhu > wieuhwi > START > Line 3 > Line 4 > END > wkwwef > wefwef > EOD > > { > my $inWanted = 0; > local $/ = qq{START\n}; > while ( not eof $inFH ) > { > $_ = <$inFH>; > if ( $inWanted ) > { > chomp; > print; > $inWanted = 0; > $/ = qq{START\n}; > } > else > { > $inWanted = 1; > $/ = qq{END\n}; > } > } > }' Line 1 Line 2 Line 3 Line 4 $

I hope this is of interest.

Cheers,

JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://980002]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 20:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found