Yet another approach (TIMTOWTDI): set the input record separator to let you collect the log entries, stanza by stanza. IOW, look for the end of a log entry, "stop combat" and slurp what precedes that, repeatedly
Borrowing from and extending roboticus' excellent sample data:
#!/usr/bin/perl use 5.014; # 971051 $/ = "stop combat"; my @array; my $stanza; for ( <DATA> ) { push @array, $_; } for $stanza ( @array ) { $stanza =~ s/\n/ /g; if ( $stanza =~ /.*?(?=start combat!)(.*?)(?=stop combat)/s ) { my $values = $1; $values =~ s/start combat!//; say "Log Entry: $values"; } else { say "Whoops."; } } __DATA__ soon the combat will begin start combat! Biff! Pow! Bam! (Looks like Batman!) stop combat fight had three superlatives start combat! Smash Bang Boom! stop combat more garbage... here (even tho log is not described as having non-value inclusions. start combat! foo stop combat
Output:
Log Entry: Biff! Pow! Bam! (Looks like Batman!) Log Entry: Smash Bang Boom! Log Entry: foo
In reply to Re: Split files based on regexp
by ww
in thread Split files based on regexp
by TonySoprano
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |