Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert apache log date format to epoch in bash

My goal is to convert dates from my apache logs in the format "12/Nov/2015:23:28:22" to epoch format. Can this be done using the date command or do I need to parse and extract the information?

like image 880
user2704766 Avatar asked Nov 14 '15 20:11

user2704766


1 Answers

It seems my date command wants - instead of / between the date parts and that to be separated by a space from the time part. So I used sed to do the conversion like so:

date -d "$(echo '12/Nov/2015:23:28:22' | sed -e 's,/,-,g' -e 's,:, ,')" +"%s"
like image 67
Eric Renouf Avatar answered Oct 25 '22 09:10

Eric Renouf