How do you use sed from Perl?

前端 未结 10 590
渐次进展
渐次进展 2021-01-18 01:14

I know how to use sed with grep, but within Perl the below fails. How can one get sed to work within a Perl program?

c         


        
10条回答
  •  轮回少年
    2021-01-18 01:23

    Anything you need to do with grep or sed can be done natively in perl more easily. For instance (this is roughly right, but probably wrong):

    my @linenumbers;
    open FH "<$fileToProcess";
    while ()
    {
       next if (!m/textToFind/);
       chomp;
       s/^\([0-9]*\)[:].*/\1/;
       push @lineNumbers, $_;
    }
    

提交回复
热议问题