Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Getting lines in a file between two patterns

by awohld (Hermit)
on Jul 05, 2012 at 06:22 UTC ( #979958=note: print w/replies, xml ) Need Help??


in reply to Getting lines in a file between two patterns

First I changed the default line delimiter to 'END'. Then I went through each record and did a multi-line regex to match what is between START and END.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; # change line delimter $/ = "END"; while (<DATA>) { my $line = $_; # match REGEX across multiple lines $line =~ /START(.*)END/s; # get the match my $contents = $1; print Dumper $contents if defined $contents;; } __DATA__ XXXX YYYY START These are the first set of lines which are to be extracted END XXX ZZZ YYY START These are the second set of lines which are to be extracted END aasds tteret tertetr

Replies are listed 'Best First'.
Re^2: Getting lines in a file between two patterns
by darklord_999 (Acolyte) on Jul 05, 2012 at 08:33 UTC
    Thanks everyone. And Utilitarian's solution worked :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2020-11-30 23:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?