Perl: How to print next line after matching a pattern?

后端 未结 7 1945
刺人心
刺人心 2021-01-06 15:52

I would like to print specific data after matching a pattern or line. I have a file like this:

#******************************    
List : car  
Design: S           


        
7条回答
  •  囚心锁ツ
    2021-01-06 16:14

    Something like this:

    while (my $line = <>) {
        next unless $line =~ /Car\s+Type/;
        next unless $line = <> and $line =~ /^#----/;
        next unless $line = <>;
        my @fields = split ' ', $line;
        print "@fields[0,1]\n";
    }
    

提交回复
热议问题