monger has asked for the wisdom of the Perl Monks concerning the following question:
What I am doing is using perl, and likely awk, for normalization for a DB project. First, I'm stripping off everything up through "WARNGING" - DONE.
Next, I need to adjust the date, converting the month to it's numerical. I'm using a hash now; if there's a better way, I'm all ears.
Finally, I need to split, or remove, the tags before each IP, and also convert the "/port number" to a "space" "port number"
Here's the code:
Without the hash search and replace, the entire log entry minus everything up through "WARNING" is in $2. I now need to operate on the contents of $2, or find a different way to pass the file down through the different filters.use Data::Dumper; my %date_hash = ( "Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04", "May" => "05", "Jun" => "06", "Aug" => "07", "Sep" => "08", "Oct" => "10", "Nov" => "11", "Dec" => "12" ); my $file=".\\tmp.txt"; my $out=".\\out.txt"; open FILE, $file || die "Can't open file: $!"; open OUT, ">$out" || die "Can't open file: $!"; while(<FILE>){ (m/(.+.WARNING)(.+)/g) while ( (my $key, my $value) = each(%date_hash)) { if (s/$key/$value/g) { } } } } close FILE; print Dumper($2); close OUT;
Peace and Pleasure in Perl coding,
monger
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiple Search and Replaces on one file
by holli (Abbot) on Jun 15, 2005 at 15:18 UTC | |
|
Re: Multiple Search and Replaces on one file
by ww (Archbishop) on Jun 15, 2005 at 15:55 UTC | |
by kaif (Friar) on Jun 15, 2005 at 16:13 UTC | |
by monger (Friar) on Jun 15, 2005 at 17:18 UTC | |
by ww (Archbishop) on Jun 15, 2005 at 17:40 UTC | |
| |
|
Re: Multiple Search and Replaces on one file
by davidrw (Prior) on Jun 15, 2005 at 15:15 UTC | |
by Elijah (Hermit) on Jun 15, 2005 at 15:38 UTC | |
|
Re: Multiple Search and Replaces on one file
by Elijah (Hermit) on Jun 15, 2005 at 15:35 UTC | |
by fishbot_v2 (Chaplain) on Jun 15, 2005 at 19:32 UTC | |
by Elijah (Hermit) on Jun 15, 2005 at 21:55 UTC | |
by fishbot_v2 (Chaplain) on Jun 15, 2005 at 22:11 UTC | |
|
Re: Multiple Search and Replaces on one file
by robot_tourist (Hermit) on Jun 16, 2005 at 14:56 UTC |