Please use  <code> ... </code> code tags for code, command line invocations, error messages and input/output data. Please see Writeup Formatting Tips, Markup in the Monastery and How do I post a question effectively? (and hopefully also How do I change/delete my post?). Please see also Short, Self-Contained, Correct Example.

Something like this (insofar as I understand your input) can be done as a command line one-liner, but it gets messy and I prefer to write a script for it, something like
    perl print-chunks.pl  < input.file  > output.file
that might look like (untested | semi-tested):

use strict; use warnings; my $rx_start = qr{ \A \s* PATTERN1 }xms; my $rx_stop = qr{ \A \s* PATTERN3 }xms; my @records; RECORD: while (my $record = <STDIN>) { if ($record =~ $rx_start) { # push @records, $record; # UPDATE: NO: still "greedy" extracti +on of records/lines @records = $record; # UPDATE: FIXED: only extracts BETWEE +N start/stop patterns next RECORD; } if ($record =~ $rx_stop) { print @records, $record; @records = (); next RECORD; } push @records, $record if @records; } exit;

Update: Example code fixed to extract records only between the start/stop patterns. Any reformatting of output that may be needed is still not addressed.


Give a man a fish:  <%-{-{-{-<


In reply to Re: command line perl command to get between lines with non greedy match (updated) by AnomalousMonk
in thread command line perl command to get between lines with non greedy match by ravi_perl_monks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.