[Sderby] perl question

Andrew White milky at toth.org.uk
Thu Jan 15 15:46:23 GMT 2004


> Hi Guys
> 
> I've got a log file from MMDF, and I need to convert the time and date part
> of each entry to something readable!
> 
> the format is like....
> 
> 1074116680.910    193.129.29.1    Some text
> 
> I found Perl can convert the time by using.... print ctime(1074116680.910),
> but I need to make a script to read the logfile and the 700 entries,
> outputting to a new file with a nice readable date and time, but keeping the
> other two bits of information, IP address and message intact.

assuming input file is 'a' and output 'b', then:

open(A,"a");
open(B,">b");
while(<A>) {
        /([\d\.]+)(\s+.*)/;
	print B scalar(localtime($1)) . $2;
}

close(a); close(B);


if you wanted to read only 700 lines, then you'd need a counter in the loop,
and break out of it with 'last;' at the 700th count.

I'm sure it makes perfect sense. It's just a regexp matching, and then
printing out the scalar of locatime for the first (scalar returning
a formatted string, rather than an array of seconds/minutes/hours/days/weeks,
etc.) and the rest of the string.

that should do it

Andy

-- 
Andrew White - jabb0r: milkydood at jabber.org, ICQ: 13892254



More information about the Sderby mailing list