【发布时间】:2013-05-07 18:10:37
【问题描述】:
我需要编写一个 perl 脚本来提取匹配不同模式的行,然后对其进行操作。我已经完成了以下匹配并提取了所有包含匹配模式的行:
my $filetoread = <$curr_dir/p*.out>;
my $filetoreadStrings=`strings $filetoread | egrep \"(Preparing extraction | 100.00%)\"`;
my @ftr = split('\n', $filetoreadStrings);
chomp (@ftr);
my $FirstPattern = (grep /Preparing extraction/, @ftr)[0];
my $SecondPattern = (grep /100.00% done/, @ftr)[0];
print "$FirstPattern \n";
print "$SecondPattern \n";
我只得到第二个模式的行,即使第一个模式(准备提取)存在于日志中。我认为问题在于或'|'。我需要知道如何获得与模式匹配的所有行。 [$curr_dir 是我运行脚本的目录,P*.out 是日志文件]
【问题讨论】: