Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Getting lines in a file between two patterns

by johngg (Canon)
on Jul 05, 2012 at 09:45 UTC ( #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
Node Status?
node history
Node Type: note [id://980002]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2020-12-01 00:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?