in reply to [Solved]Need to extract a particular block of lines between two patterns

This solution makes use of the next if 1 .. /^END$/; flip flop operator. The 1 is the first line of the file to the first END. The next time it encounters a START END block, it performs the actions in the code.
#!/usr/bin/perl use strict; use warnings; while (<>) { next if 1 .. /^END$/; if (/^START$/ .. /^END$/) { next if /^START$/; last if /^END$/; print; } }
This works for the data sample you provided.

Replies are listed 'Best First'.
Re^2: [Solved]Need to extract a particular block of lines between two patterns
by chengchl (Acolyte) on Nov 11, 2017 at 01:38 UTC

    Hi Cristoforo,

    Thank you so much for your help. Please correct me if I understand it wrong - the code will skip the first START ... END pattern but will output the all the following patterns right? That is to say, the third START .. END pattern will be printed out as well even if it's not wanted?

    Thank you so much for the help again!

      Yes, it will skip the first block. It will exit the while loop (last if /^END$/) when it reaches the END for the second block.