Perl 打印关键字上下行

前端之家收集整理的这篇文章主要介绍了Perl 打印关键字上下行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/usr/bin/perl 
$dir  = '/home/MysqL';
$file = '1.log';
$mon_file = "$dir/$file";
print "\$mon_file is $mon_file\n";
@warn_arr = qw/连接已关闭 连接超时 NullPointException IndexOutOfBound exception/;
foreach $a (@warn_arr) {
    undef @err_info;
    open( C,"<","$a.tmp" );
    while (<C>) {
        $count = $_;
    }
    print "$a is $count";

    open( A,"$mon_file" ) || die "$!\n";
    $i   = 0;
    $num = 0;
    while (<A>) {
        $num++;
        if ( $_ =~ /$a/i ) { $i++; $b = $num }
    }
    print "\$b is $b\n";

    if ( $i != 0 && $i != $count && defined($count) ) {
        open( B,"$mon_file" ) || die "$!\n";
        while (<B>) {
            chomp($_);
            push( @err_info,$_ ) if ( $. >= $b - 5 and $. <= $b + 5 );
        }
        print "\@err_info is @err_info\n";
        system("SMSsendx  111111111 \"@err_info\" 10.10.10.10");
    }

    open( C,">","$a.tmp" );

    print C ("$i\n");

}

猜你在找的Perl相关文章