テキスト ファイルがあり、パターンで始まり特定のパターンで終わる特定の行を取得したいと考えています。例:
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);
よろしくお願いします。