in reply to Re^4: Getting lines in a file between two patterns
in thread Getting lines in a file between two patterns
Push lines to an array, clear it at each START.
poj#!/usr/bin/perl use strict; my $flag = 0; my @lines = (); while (<DATA>){ if (/^\s*END/){ $flag = 0 } elsif (/^\s*START/){ $flag = 1; @lines = (); } elsif ($flag) { push @lines,$_; } } print join '',@lines;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Getting lines in a file between two patterns
by Anonymous Monk on May 17, 2018 at 18:17 UTC | |
by poj (Abbot) on May 17, 2018 at 19:54 UTC |
In Section
Seekers of Perl Wisdom