Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Parsing a log file

by TStanley (Canon)
on Nov 27, 2007 at 19:03 UTC ( #653340=note: print w/ replies, xml ) Need Help??

in reply to Parsing a log file

And for curiosity's sake, here is the final script:

#!perl use strict; my $DATE= do { my($y,$m,$d)= (localtime(time-60*60*(12+(localtime)[2]) + ))[5,4,3]; sprintf "%04d-%02d-%02d", 1900+$y, 1+$m, $d; }; open INPUT,"<","SyslogCatchAll.txt"||die "Can not open input file: $!\ +n"; open CSV,">","$DATE.csv"||die "Can not open $DATE.csv: $!\n"; print CSV "Date,Time,WS 2000,FW Date,FW Time,Store,Src IP,Src Port,Dst + IP,Dst Port,Type,Agent,Message\n"; while(<INPUT>){ $_=~m/msg=(.*) Src/; my $msg = $1; my @line = split /\s+/; my $Date = $line[0]; next if ($Date ne $DATE); my $Time = $line[1]; my $ws2k = $line[3]; my $FWD = $line[5]; my $FWT = $line[6]; my $store = $line[8]; my $src_ip = $line[11]; my $dst_ip = $line[12]; my $src_prt = $line[$#line - 6]; my $dst_prt = $line[$#line - 4]; my $type = $line[$#line - 2]; my $agent = $line[$#line]; chomp $agent; $agent=~s/agent=//; $FWD=~s/time="//; $FWT=~s/"//; $src_ip=~s/src=//; $dst_ip=~s/dst=//; $msg=~s/,/ /; print CSV "$Date,$Time,$ws2k,$FWD,$FWT,$store,$src_ip,$src_prt,$dst_ +ip,$dst_prt,$type,$agent,$msg\n"; } close INPUT; close CSV;

People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf. -- George Orwell

Comment on Re: Parsing a log file
Download Code
Replies are listed 'Best First'.
Re^2: Parsing a log file
by Nkuvu (Priest) on Nov 28, 2007 at 16:53 UTC

    I have to admit, I'm confused.

    Why ask for suggestions, then disregard them all and make the script exactly like you had in the opening post? Obviously if it's working for you then that's great, but I'm missing the point of asking for advice just to ask.

    And why make a new note for the final script rather than just updating the original node with something like "update: went with the script as is" ?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://653340]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2015-11-29 19:37 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (753 votes), past polls