Converting Apache log date format to era in bash

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

+5
source share
2 answers

It seems my date command wants - instead of / between the parts of the date, and to separate the space from the time part. Therefore, I used sed to convert as follows:

 date -d "$(echo '12/Nov/2015:23:28:22' | sed -e 's,/,-,g' -e 's,:, ,')" +"%s" 
+8
source

You can use the dateutils package:

dateutils.strptime -i "%Y%m%dT%H%M%S" -f "%d.%m.%Y %H:%M:%S" "20170411T172238"

where -i is your input format and -f output format

0
source

Source: https://habr.com/ru/post/1235965/


All Articles