in reply to Re: extract lines between same pattern
in thread extract lines between same pattern

use FileHandle; $fh = new FileHandle '<input.txt'; $in_body = 0; while (<$fh>) { if ($in_body) { if (m{SUMMARY.*?>}i) { $in_body = 0; } else { ($row1, $row2) = split ; # print "$row1", "\t", "$row2" , "\n"; print; } } elsif (m{/SUMMARY.*?>}i) { $in_body = 1; # print; }
Here i can get the data where the end is /SUMMARY. For the column data I want to convert to row data. So that i would have:
summary col1 col2 col3 .... SUMMARY XXXX SUMMARY YYY

Replies are listed 'Best First'.
Re^3: extract lines between same pattern
by FloydATC (Deacon) on May 27, 2009 at 12:56 UTC
    If you use parens, like m/SUMMARY\s(.*)\n/i then $1 will contain whatever matched .*

    -- Time flies when you don't know what you're doing
      sorry could you give an example - not sure what you mean here? thanks