develooper Front page | perl.beginners | Postings from December 2002

Re: Working with Log Files

Thread Previous | Thread Next
From:
John W. Krahn
Date:
December 1, 2002 00:14
Subject:
Re: Working with Log Files
Message ID:
3DE9C4A4.DF00BB4B@acm.org
Tim Martin wrote:
> 
> My new manager wants me to learn perl and start with understanding logs
> files from 50 plus servers.
> I hope I have sent this message to the correct perl form.
> I have a sample of the logs below that need to be fixed using perl.
> Any ideas or suggestion will be helpful.
> 
> =============  Start of log sample  =============
> 
> 1.  REMOVE ALL WHITE SPACE GREATER THEN ONE.
> 
> [snip]
> ===========================================================================
> 
> 2.  ENSURE EACH LINE IN THE LOG START WITH A DATE AND TIME
>      REMOVE THE CARRIAGE RETURN AND LINE FEED
>      INSERT ONE WHITE SPACE
> 
> [snip]
> ===========================================================================
> 
> 3.  ENSURE EACH LINE IN THE LOG START WITH A DATE AND TIME
>      REMOVE THE CARRIAGE RETURN AND LINE FEED
>      INSERT ONE WHITE SPACE
>      REMOVE ALL BLANK LINES FROM LOGS
> 
> [snip]
> =============  End of log sample  =============


perl -lane'eof||m!^\d{4}/\d\d/\d\d\s+\d\d:\d\d:\d\d\s!?((@X&&print"@X"),@X=@F):push@X,@F' logfiles*



John
-- 
use Perl;
program
fulfillment

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About