in reply to skipping lines in a file until regexp matches
Update: That should probably be (the first version only prints the start pattern once, this version will print it every time it occurs):my $start_pattern = qr/.... $date/; my $end_pattern = qr/.... $date/; my $send_pattern = qr/.... whatever/; while (<LOG>) { if (my $status = /$start_pattern/..1) { print "$. : $_" if $status == 1 or /$end_pattern/ or /$send_pattern/; } }
Another update: After dropping the status, I'd go with an answer with a 'next unless' like dpuu's answer below.while (<LOG>) { if (/$start_pattern/..1) { print "$. : $_" if /$start_pattern/ or /$end_pattern/ or /$send_pattern/; } }
|
---|