use strict; my $counter=1; $/="</Rec $counter>"; my $first_file; my $second_file; while (my $record=<DATA>) { $first_file .= $record unless $record=~m/var2 = 3/; $second_file .= $record if $record=~m/var2 = 3/; $counter++; $/="</Rec $counter>"; } print "FIRST FILE: $first_file\nSECOND FILE: $second_file\n";
__DATA__ <Rec 1> var2 = 5 some text some text some text some text </Rec 1> <rec 2> var2 = 3 some text some text some text some text some text some text some text some text </Rec 2> <Rec 3> var2 = 7 some text some text some text some text some text some text </Rec 3> <rec 4> var2 = 3 some text some text some text some text some text some text some text some text </Rec 4>
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
In reply to Re: help: extracting multiple lines from file based on match in one line
by CountZero
in thread help: extracting multiple lines from file based on match in one line
by my_perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |