Possible Duplicate:
Convert date formats in bash
I need to convert a date such as
2012-06-01T19:05:00+02:00
to something like this
01-06-2012 19:05
Ideally using sed or awk. How do I do this?
Possible Duplicate:
Convert date formats in bash
I need to convert a date such as
2012-06-01T19:05:00+02:00
to something like this
01-06-2012 19:05
Ideally using sed or awk. How do I do this?
This can be done without resorting to sed or awk, since bash itself can do most of the required string replacements. Specifically, you just need to:
The rest of the date formatting can be handled by the date command.
$ date_string='2012-06-01T19:05:00+02:00'
$ date_string="${date_string/T/ }"
$ date_string="${date_string/+*/}"
$ date -d "$date_string" '+%d-%m-%Y %H:%M'
01-06-2012 19:05
echo "2012-06-01T19:05:00+02:00"|sed 's/\(.*\)T\([0-9]*:[0-9]*\).*/\1 \2/'
2012-06-01 19:05
To explain what it does:
date -d "$(echo '2012-06-01T19:05:00+02:00' | sed 's/T/ /; s/+.*//')" '+%d-%m-%Y %H:%M'