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
In reply to Multiple Search and Replaces on one file by monger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |