我有一个文本文件,想要获取以某个模式开头并以特定模式结尾的特定行。
例如:
Text
Text
Startpattern
print this line
Print this line
print this line
Endpattern
Text
Text
Text
同时需要打印开始模式和结束模式。我的第一次尝试并不成功:
my $LOGFILE = "/var/log/logfile";
my @array;
# open the file (or die trying)
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.