Convert Squid/timestamps to a human readable format

Somebody had the brilliant idea of using Unix timestamps in Squid log files. It makes parsing easy but reading them is not so human-friendly.

This is an elegant way of solving the problem:

cat /var/log/squid/access.log | perl -p -e 's/^([0-9]*)/"[" . localtime($1) . "]"/e'

The Perl one-liner captures the timestamp at the beginning of each line, converts it to a human-readable date with localtime(), and replaces it inline. The /e flag tells Perl to evaluate the replacement as code rather than a string.

Hope it helps!

One thought on “Convert Squid/timestamps to a human readable format”

  1. Good article! We are linking to this great post on our website. Keep up the great writing. Maggee Justinian Oneal

Leave a Reply

Your email address will not be published. Required fields are marked *