I have a text file, and I want to capture certain lines, starting from a template and ending with a specific template. Example:
Text
Text
Startpattern
print this line
Print this line
print this line
Endpattern
Text
Text
Text
A start pattern and an end pattern should also be printed. My first attempt was not really successful:
my $LOGFILE = "/var/log/logfile";
my @array;
open(LOGFILE) or die("Could not open log file.");
foreach $line () {
if($line =~ m/Sstartpattern/i){
print $line;
foreach $line2 () {
if(!$line =~ m/Endpattern/i){
print $line2;
}
}
}
}
close(LOGFILE);
Thanks in advance for your help.
source
share