我有一个 Test.txt 文件,如下所示:
some data1 func-name1 SECTION.
data to be extracted
data to be extracted
some data2 func-name2 SECTION.
data to be extracted
data to be extracted
func-name2-EXIT. EXIT.
现在,我正在使用触发器运算符来提取范围,其中我的 START= SECTION。和 END= - 退出。出口。如下:
open FILE1, "<Test.txt"
or die "Cannot open File1.txt!";
open FINAL, ">Final.txt"
or die "Cannot open Finall.txt!";
my $START = 'SECTION.';
my $END = '-EXIT EXIT.';
while (<FILE1>) {
if (/$START/ .. /$END|$START/) {
if ($_ =~ m/$END|$START/) {
$flag = 1;
}
print FINAL $_;
if ($flag == 1) {
print FINAL "\n\n";
$flag = 0;
}
}
}
close FINAL;
close FILE1;
我想要做的是,我需要两个下一行作为SECTION 之间的分隔符。范围也和我的 Final.txt 应该如下所示:
some data1 func-name1 SECTION.
data to be extracted
data to be extracted
some data2 func-name2 SECTION.
data to be extracted
data to be extracted
func-name2-EXIT. EXIT.
请指导我。