Converting Unix Timestamp fields in a Log File from the Shell

I recently wanted to get a view on the date/times of entries in some Nagios logs I was working with in the shell, e.g. when did their entries start and end, etc. The logs are tab-delimited with a Unix timestamp in the first field. Googling around led me to the following nifty technique using awk:

$ head service-event.out | awk '{print strftime("%c",$1)}'
Thu, Jan 31, 2013  9:49:20 PM
Thu, Jan 31, 2013  9:51:23 PM
Thu, Jan 31, 2013 10:21:03 PM
Thu, Jan 31, 2013 10:23:03 PM
Fri, Feb 01, 2013 10:07:55 AM
Fri, Feb 01, 2013 10:09:55 AM
Fri, Feb 01, 2013 10:36:18 AM
Fri, Feb 01, 2013 10:38:18 AM
Fri, Feb 01, 2013 11:40:58 AM
Fri, Feb 01, 2013 11:41:19 AM

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>