How To Replace A String In File With A String Containing Windows File Path

Hi,

I have a file with the following contents

# Lines that start with a # are comments.
#
# Calling TOAD like this will perform a comparison from command line :
#
# "C:\Program Files\Quest Software\Toad for Oracle 9.6\toad.exe" -c "SPE/<7,0,0,3,93,182,138,123,109,122,232,120,215,188,75,211,220,108,95,91>@MYDB" COMP
="D:\TOAD611\TEMPLATE.txt"
#
# Obviously, your path to TOAD may differ, along with your connect info.
# The file name after "COMP=" is the name of this file.
#
# Uncomment and edit the following line to load a saved object set
# from a text file.
# LoadObjectSet('c:\MyObjectSet.txt')
#
# To disable the Team Coding login prompt:
# Add "TC=NO" (without the quotes) in the command line string.

As Highlighted above i would like to replace D:\TOAD611\ path to I:\ToadControlFiles\${ENV}\${SID}\

The value of $ENV= TEST and $SID=mydb. These are basically being captured as arguments when we invoke the shell script.

I have tried the the below methods

### USING AWK###########

export SID=$1
export ENV=$2
eval `export STRING="I:\\ToadControlFiles\\${ENV}\\${SID}\\"`
echo ${STRING}

nawk -v m=${STRING} '{gsub(/D\:\\TOAD611\\/, m, $0); print }' TEMPLATE.TXT

### USING SED###########

export SID=$1
export ENV=$2
eval `export STRING="I:\\ToadControlFiles\\${ENV}\\${SID}\\"`
echo ${STRING}

sed 's/D\:\\TOAD611\\/'${STRING}'/g' TEMPLATE.TXT

### USING PERL###########

export SID=$1
export ENV=$2
eval `export STRING="I:\\ToadControlFiles\\${ENV}\\${SID}\\"`
echo ${STRING}

perl -pi -e 's/D:\\TOAD611\\/$STRING/g' TEMPLATE

In all the above attempts its failing to retain the "\" of the windows path its replaces with something like this I:ToadControlFilesTESTmydb

As solutions please... Basically i need a method that will replace one windows path with another constructed windows path. Since the windows path has "\" characters it gets lost when the final string replacement is done.

Thanks and Kind Regards,
Rajan.S

It looks like you're not escaping enough:

s/D/D\:\\/

would print: D:\

The 'correct' number of escapes would then be:

s/D/D\:\\\\/

Hi,

Yes you were right the below pretty much handles to what i exactly want

sed 's/D\:\\TOAD611\\/'I\:\\\\ToadControlFiles\\\\${ENV}\\\\${SID}\\\\'/g'

Thanks and kind regards,
Rajan