views:

25

answers:

2

I'm creating Unix bash script that parses web-server log file and inserts this data into database. So I need to convert timestamp which has format "05/Oct/2010:07:38:40 +0400" into "YYYY-mm-dd".

I've tried to use /bin/date -d, but it does not accept given format. I could not find a way to specify input date format for this tool. Is is possible or i should consider alternative solution?

A: 

You need:

 date +%F

Also, this seems to work:

date -d "05 Oct 2010 07:38:40 +0400" +%F

You need to use spaces as separators rather than / or :.

Kedar Soparkar
A: 
input_date="05/Oct/2010:07:38:40 +0400"
better_date=`echo $input_date | sed -E 's|(..)/(...)/(.{4}).*|\1 \2 \3|'`
date -I -d "$better_date"
Edgar Bonet