log file conversion (OT?)

Doug Poland wisco.disco at gmail.com
Tue Jan 3 12:05:38 PST 2006


On 11/9/05, Giorgos Keramidas <keramida at ceid.upatras.gr> wrote:
> On 2005-11-09 13:44, Bart Silverstrim <bsilverstrim at athensasd.org> wrote:
> > On Nov 9, 2005, at 1:03 PM, Giorgos Keramidas wrote:
> > >Yes.  Perl should work fine here.
> > >
> > >    $ echo '1131556815.537    101 172.16.2.153 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
> >
Thank you, Giorgos, for that excellent Perl one-liner.  There is a
minor problem in that not all the input fields are output correctly. 
Note the IP address is truncated.   I took the liberty of fixing and
simplifiing (or, obfuscating, depending on one's point of view)

tail -f /usr/local/squid/logs/access.log | \
  perl -MPOSIX=strftime -ane \
  '$F[0] = strftime "%Y-%m-%d %H:%M:%S", (localtime($F[0])); \
  print join(" ", @F) . "\n";'


--
Regards,
Doug


More information about the freebsd-questions mailing list