Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: How to monitor a logfile with columns for certain data?

by gamache (Friar)
on Nov 16, 2007 at 16:39 UTC ( [id://651262]=note: print w/replies, xml ) Need Help??


in reply to How to monitor a logfile with columns for certain data?

Having worked with a lot of fixed-length data (Fortran output), I've done it like this:
#!/usr/bin/perl use strict; use warnings; <DATA>; <DATA>; # skip header lines while (<DATA>) { my @fields = / (.{51}) (.{21}) (.{21}) (.{21}) (.+) /x or next; my @fields_nospace = map {/^\s*(.+?)\s*$/; $1} @fields; print join ("\t", @fields_nospace), "\n"; } __DATA__ (your data here)
Output:
N-20070143.003.TXT 05/23/07 02:36:59 PM 13 13 0 N-20070143.004.TXT 05/23/07 04:48:56 PM 1 1 0 N-20070143.006.TXT 05/23/07 04:48:56 PM 16 16 0 N-20070143.008.TXT 05/23/07 04:48:58 PM 19 19 0 N-20070143.009.TXT 05/23/07 04:48:59 PM 1 1 0 N-20070143.010.TXT 05/23/07 04:49:00 PM 5 4 1 N-20070143.012.TXT 05/23/07 04:49:00 PM 18 18 0 N-20070143.013.TXT 05/23/07 04:49:02 PM 20 20 0 N-20070143.015.TXT 05/23/07 04:49:03 PM 53 53 0 N-20070143.011.TXT 05/24/07 04:35:48 PM 5 5 0 N-20070152.040.TXT 06/18/07 04:03:26 PM 25 21 4

Replies are listed 'Best First'.
Re^2: How to monitor a logfile with columns for certain data?
by freddiel (Initiate) on Nov 16, 2007 at 17:01 UTC
    Ok, So how do I retrieve the column that has Header of Errors and get the line that has Errors > 0 or Processed <>Total Records? Any information would be greatful. I am not very good at perl. Thanks.
      Each field is an element in the @fields_nospace array; the first field (File Name) is at $fields_nospace[0], and the fifth field (Errors) is at $fields_nospace[4]. So you can check if $fields_nospace[4] > 0, or if $fields_nospace[2] != $fields_nospace[3], and do things based on those conditions. Hope this helps.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-18 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found