Greetings monestarians, I am working on parsing a log file. Here's a snippet:
6/13/2005 5:59:57 PM 10.1.1.2 WARNING Jun 13 2005 22:00:04: %PIX-4-106023: Deny udp src aliens:192.168.1.35/1148 dst dmz:10.10.10.32/1434 by access-group "aliens"

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:

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;
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.

Peace and Pleasure in Perl coding,
monger

Monger +++++++++++++++++++++++++ Munging Perl on the side

In reply to Multiple Search and Replaces on one file by monger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.