Formatting a string

hi,
i am relatively new to unix. i have a doubt

i have a string in the format "2010-10-27 15:03:56"
i need to format that to "10/27/2010 15:03:56" this format
how to do that in unix script ?

any help is appreciated..

SRC="2010-10-27 15:03:56"
DEST=`echo $SRC | ( IFS="- " read Y M D rest; echo "$D/$M/$Y $rest" )`

also try:

var="2010-10-27 15:03:56"
newvar=$(echo "$var"  | tr -s  '-'   '/'  )

UNIX usually has several ways to do one thing - pick the one you like.

OP also wanted to translate from YMD to DMY format

Good point my example is wrong in that case.

with GNU date

date -d "2010-10-27 15:03:56" "+%m/%d/%Y %H:%M:%S"
S="2010-10-27 15:03:56"
DEST="${S:8:2}/${S:5:2}/${S::4} ${S#* }"
str="2010-10-27 15:03:56"
newstr=$( IFS=- ; set -- ${str% *}; echo "$2/$3/$1 ${str#* }" )