How to convert an epoch second to a python datetime object?

The Epoch second (POSIX time/Unix time) is the number of seconds that have elapsed since January 1, 1970. Epoch seconds are not counting leap seconds.

So how we can convert an epoch second to human readable time?

For that, first we need to create a datetime object for the day 1970/Jan/01

then put the epoch second which you would like to convert to a human readble format in a varaible

then create a timedelta object for the epoch_second

then add dobj1 to dobj2

or in short

AWK practical tips for parsing access logs

#1 Find top 10 IPs from an access log

Now you can pipe the output to a pipe and can find top 10 IPs using sort and head -10

#2 Suppose you have an access log which have timestamp in epoch seconds like following and you want to print hourly QPS count

Now you know how to get an hourly data and you know how to pass bash variable inside awk. So using a for loop, right you can get data for all hours separately


  • I tested this in awk version 3.1.7. You can find your awk version using awk –version
  • Assuming log is getting rotated every day

Click me for the official page of AWK