in reply to Lines above and Below a matched string
If the file is small, slurp the whole file into a scalar and use a regex of the general form
my $data = do{ local (*ARGV, $/) = 'text.file'; <>; }; print "$2,$1,$3" if $data =~ m[(DATE).*?(SOMETHING).*?(SOMETHINGELSE)]s;
The /s modifier allows . to match newlines, so the .*? will span lines. Add /g if you expect to find more than one occurance.
If your file is too big to slurp, then you could use a sliding buffer on the file. See Re: split and sysread() for some sample code.
|
|---|