log file conversion (OT?)

Giorgos Keramidas keramida at ceid.upatras.gr
Wed Nov 9 18:03:58 GMT 2005

On 2005-11-09 12:36, Bart Silverstrim <bsilverstrim at athensasd.org> wrote:
> I have Squid running on a FreeBSD system and the log file (access.log)
> has lines like
> 1131556815.537    101 TCP_HIT/200 35674 GET
> http://www.urprize2.com/adv77/images/header_08_23_05.gif - NONE/-
> image/gif
> 1131556815.584     47 TCP_HIT/200 1828 GET
> http://www.urprize2.com/adv77/images/timer.swf - NONE/-
> application/x-shockwave-flash
> in it.  Is there a simple way or a one- or two-liner script
> that can take the epoch time in the first column and replace it
> with the actual time/date stamp in human-readable format?

Yes.  Perl should work fine here.

    $ echo '1131556815.537    101 TCP_HIT/200 35674 GET' | \
      perl -MPOSIX=strftime \
      -pe 'chomp; @x=split /\./; \
           $ts = strftime "%Y-%m-%d %H:%M:%S", (localtime($x[0])); \
           $_=$ts.".".join(".", at x[1,$#x])."\n";'
    2005-11-09 09:20:15.537    101 172.153 TCP_HIT/200 35674 GET

PS: Please, ignore the automatically forced 'footer' below, until
I find a way to post messages without crap added automatically by
the Exchange relay I'm forced to use these days.


This e-mail and any attachments may contain confidential and
privileged information. If you are not the intended recipient,
please notify the sender immediately by return e-mail, do not forward 
this email to any other person, delete this
e-mail and destroy all copies. Any dissemination or use of this
information by a person other than the intended recipient is
unauthorized and may be illegal.

More information about the freebsd-questions mailing list