Display date in mm/dd/yy format in sed command

Hi All,

Following is my issue.

$MAIL_DOC = test.txt
test.txt contains the following text .

This process was executed in the  %INSTANCE% instance on %RUNDATE%.
I am trying to execute the following script
var=`echo $ORACLE_SID | tr [a-z] [A-Z]`
NOW=$(date +"%D")
sed -e "s/\%INSTANCE\%/$var/g;s/\%RUNDATE\%/$NOW/g" $MAIL_DOC

I am trying to display the current date in mm/dd/yy format.
Thats where the issue is .
If I try to display in mm-dd-yy format using date '+%m-%d-%Y' I do not have any issues.
But if I try to display in mm/dd/yy format using date +"%D" , I get sed command garbled.
Will sed command and date +"%D" format don't work ?
Please help.

Thanks
Megha.

I've seen on some occasions that changing the delimiter for sed works:

export NOW=$(date '+%D')

echo "then" | sed "s/then/$NOW/"
sed: -e expression #1, char 13: unknown option to `s'

echo "then" | sed "s|then|$NOW|"
03/04/13

Use a '#' sign for sed delimiter instead of a '/':
echo RUNDATE | sed "s#RUNDATE#$NOW#g"

1 Like

Thank you everyone for the prompt reply.
I changed the delimiter in the sed command to # and it worked.
Thanks again
Megha.