美文网首页
perl 读取匹配行之后的内容

perl 读取匹配行之后的内容

作者: 线断木偶人 | 来源:发表于2019-02-15 11:54 被阅读0次

我的文件内容如下,只读取匹配到了2之后的内容;

#cat file.txt
111111111111
111111111111
111111111111
111111111111

222222222222
222222222222

3333333333333
3333333333333
3333333333333

代码如下:

#!/uer/bin/perl -w
usr strict;
open B,$ARGV[0] or die;
while(<B>){
    chomp;
    if (/\[^222\]/) {
    $line_num = $. + 1;
    }

    next if ($line_num == 0);
    if ($. > $line_num){
        print "$_\n";
        }
    }
}

相关文章

网友评论

      本文标题:perl 读取匹配行之后的内容

      本文链接:https://www.haomeiwen.com/subject/grepeqtx.html