Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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;

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

In reply to Re: Parsing a log file by TStanley
in thread Parsing a log file by TStanley

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (9)
    As of 2014-07-25 19:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (174 votes), past polls