Operating System - Linux
1828349 Members
3054 Online
109976 Solutions
New Discussion

Re: PERL scripting - help

 
Rahul_13
Advisor

PERL scripting - help

Hi,

Please find attached a log file which is my input file.

I need to extract the portion of the log which is for the last 2 hours and parse that to generate the output which looks like this:

Hostname Error Code time range


The error code is the 4th field in the input. It is successful if the code is "000" and failure otherwise.

I just need all the error codes for the last 2 hours for the day in my output.

Hostname should be the name of the server.

Can anyone please help me to write the script using PERL.

Thanks,
Rahul

2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor

Re: PERL scripting - help

1) I don't see you hostname.

2) I could certainly write this but I will not when someone is too lazy to even make the attempt.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: PERL scripting - help

Hi Rahul:

I'm not sure what your fields really are. Assuming that the time period begins in the second (zero-relative) character of the second (zero-relative) field, something like this would output non-zero (e.g. "35V") results for hours greater than "9":

perl -lanF";" -e 'print $F[3] if substr($F[1],2,2) > 9 && $F[3] !~/000/' logfile

Regards!

...JRF...