I want to convert a date like
12-24-11 13:37
(MM-DD-YY MM:SS) to
11-12-24 13:37
(YY-MM-DD MM:SS)
is there anyway to do this?
I want to convert a date like
12-24-11 13:37
(MM-DD-YY MM:SS) to
11-12-24 13:37
(YY-MM-DD MM:SS)
is there anyway to do this?
sed to the rescue:
$ echo 12-24-11 13:37 | sed 's#^\([0-9\-]\{5\}\)-\([0-9]\{2\}\)#\2-\1#'
11-12-24 13:37
No sed needed.
#!/bin/sh
input="12-24-11 13:37";
month="${input%%-*}";
input="${input#*-}";
day="${input%%-*}";
input="${input#*-}";
year="${input%% *}";
input="${input#* }";
echo "$year-$month-$day $input";
But if you do want to use external tools, might as well use one with a short regex
echo 12-24-11 13:37 | perl -pe 's/(.+)-(.+) /$2-$1 /'
This should point you in the right direction - http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/