in reply to Parsing log file with blank lines for the field separator
This is for fixed strings. If you need regexes then replace the @string array with an array of regexes using qr{ } and replace the use of index with an regex call, ala $paragraph =~ $regex[$i].use strict; use warnings; my @string = ('String A', 'String B', 'String C', 'String D', 'String +E'); my @logfile = ('A.log', 'B.log', 'C.log', 'D.log', 'E.log'); my @logfh; open (IN, '<', 'input.txt') or die "Couldn't open input file!\n"; for my $i (0..$#logfile) { open ($logfh[$i], '>', $logfile[$i]) or die "Couldn't create logfi +le!\n"; } local $/ = ''; while (my $paragraph = <IN>) { for my $i (0..$#string) { if ( index($paragraph, $string[$i]) >= 0) { print {$logfh[$i]} $paragraph; } } } close IN; foreach my $fh (@logfh) { close $fh; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parsing log file with blank lines for the field separator
by chromatic (Archbishop) on May 05, 2008 at 20:01 UTC | |
by JasonJ (Initiate) on May 06, 2008 at 18:19 UTC | |
by chromatic (Archbishop) on May 06, 2008 at 20:20 UTC | |
|
Re^2: Parsing log file with blank lines for the field separator
by JasonJ (Initiate) on May 06, 2008 at 15:51 UTC |