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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |