Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Perl:匹配后打印所有行_Regex_Perl_Next - Fatal编程技术网

Regex Perl:匹配后打印所有行

Regex Perl:匹配后打印所有行,regex,perl,next,Regex,Perl,Next,我正在尝试用perl解析一个文件。我想在正则表达式匹配后打印所有行 例如,该文件是 num_of_dogs,10,#start_reading num_of_cat,15 num_birds,20 num_of_butterfly,80 ..... 我想要比赛后的所有台词#开始阅读 while (<$fh>) { next if 1 .. /#start_reading/; print; } 我试过这个,但它只打印下一行 while (my $line = <

我正在尝试用perl解析一个文件。我想在正则表达式匹配后打印所有行

例如,该文件是

num_of_dogs,10,#start_reading
num_of_cat,15
num_birds,20
num_of_butterfly,80
.....
我想要比赛后的所有台词
#开始阅读

while (<$fh>) {
    next if 1 .. /#start_reading/;
    print;
}
我试过这个,但它只打印下一行

while (my $line = <$csv_file>) {
    next unless $line =~ /(.*),#end_of_tc/;
    if ($line =~ /(.*)/){
    print $file = $1;
    }
}

提前感谢

当行中包含
#start_reading
时,您可以设置一个标志,并且仅当标志为真时才打印该行:

while (my $line = <$csv_file>) {
    print $line if $start;
    $start ||= $line =~ /#start_reading/;
}

您还可以使用触发器(
)运算符绕过从文件开头到包含
#start_reading

while (<$fh>) {
    next if 1 .. /#start_reading/;
    print;
}
while(){
下一步如果1../#开始读取/#;
印刷品;
}
这将绕过从文件第1行打印到匹配的行
#start_reading
。然后打印文件中的其余行

 perl -ne 's/.+\,#start_reading\s*/next/e; print $_' d
通过gnu sed,如果您的数据在'd'中

 sed -En '/.+,#start_reading/{:s n; $q;p; bs }' d

仅在某一点之后处理文件的一种高效、干净的方法

last if /#start_reading/ while <$csv_file>;  # get past that point in file

while (<$csv_file>) { print }                # now work on it
last if/#start#u reading/while;#通过文件中的那个点
而(){print}#现在就开始吧

while(){print if$start;$start | | |=/#start_reading/}您能通过编辑您的帖子来显示输入文件的外观吗?
while()
谢谢,以及如何停止阅读?我想在停止阅读之后停止阅读,thanks@JigarVaidya我已经用一个停止的解决方案更新了我的答案。@b如果脚本在“停止”阅读之后没有停止,它仍然会一直读到底。。。我的代码
push@loop\u reg,$line if$print$print | |=$line=~m/#lane|u loop_start/$打印&&=$line!~m/#车道#环路(停车)
last if /#start_reading/ while <$csv_file>;  # get past that point in file

while (<$csv_file>) { print }                # now work on it