I have 2007-10-03 and I want to write it as 03/10/2007
how can I do this?
[code]
string="2007-10-03"
IFS="-" && echo "$string" | read year month day
string="$day/$month/$year"
echo $string
[/code
thanks but it only writes //
and I'm afraid I couldnt understand the part:
IFS="-" && echo "$string" | read year month day
I have a question can I make an array that
its first element is "2"
second element is "0"
third element is "0"
fourth element is "7"
.....
# echo "2007-10-03" | awk 'BEGIN{FS="-";OFS="/"}{print $3,$2,$1}'
03/10/2007
thanks
You could do this with cut this way:
#!/bin/bash
OLDSTRING="2007-10-03"
YEAR=$(echo "${OLDSTRING}" | cut -d"-" -f1)
MONTH=$(echo "${OLDSTRING}" | cut -d"-" -f2)
DAY=$(echo "${OLDSTRING}" | cut -d"-" -f3)
NEWSTRING="${DAY}/${MONTH}/${YEAR}"
Just another way. Could someone give the awk example?