我想把日期转换成
12-24-11 13:37
(MM- dd - yy MM:SS)到
11-12-24 13:37
(YY-MM-DD MM: SS)
有办法这样做吗?
施救:
$ echo 12-24-11 13:37 | sed 's#^([0-9-]{5})-([0-9]{2})#2-1#'
11-12-24 13:37
不需要sed
#!/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";
但是如果你想使用外部工具,最好使用一个短的正则表达式
echo 12-24-11 13:37 | perl -pe 's/(.+)-(.+) /$2-$1 /'
这应该为您指明正确的方向- http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/