I am writing a perl program to extract lines that are in between the two patterns i am matching. for example the below text file has 6 lines. I am matching load balancer and
You can use the flip-flop operator to tell you when you are between the markers. It will also include the actual markers, so you'll need to except them from the data collection.
Note that this will mash together all the records if you have several, so if you do you need to store and reset @array
somehow.
use strict;
use warnings;
my @array;
while () {
if (/^load balancer$/ .. /^end$/) {
push @array, $_ unless /^(load balancer|end)$/;
}
}
print @array;
__DATA__
load balancer
new
old
good
bad
end