目的:对当前目录或指定目录下以.log为后缀的文件进行解析,找出符合匹配格式的错误信息的位置。
说明:仅仅是当前目录或指定目录下的文件!暂未实现,遍历目录。
代码:(文件名:xxx.pl)
use strict;
my ($eachfile,$line,$output);
$eachfile;
$line = 0;
$output = ">result.txt";
open OUT,$output or die $!;
my @myfiles = <*.log>;
for $eachfile (@myfiles) {
open FH,$eachfile or die $!;
$line = 0;
#print "\n$eachfile -> start \n";
while() {
$line++;
#print $_,"\n";
if(($_ =~ /warnings*,\s([0-9]*)\serrors,\s([0-9]*)\sserious errors/))
{
#print $1,"\n";
if($1 > 0 || $2 > 0)
{
print "result in the file: $eachfile line: $line \n";
print OUT "result in the file: $eachfile line: $line \n";
}
}
}
#print "\n$eachfile -> end \n";
close FH;
}
print "finish search ! \n";
print OUT "finish search ! \n";
close OUT;
阅读(616) | 评论(0) | 转发(0) |