4.43. How do I replace "C:\SOME\DOS\PATH" in a substitution?
For MS-DOS users, every backslash must be doubled. Thus, to replace
"C:\SOME\DOS\PATH" with "D:\MY\NEW\PATH":
sed "s|C:\\SOME\\DOS\\PATH|D:\\MY\\NEW\\PATH|g" infile >outfile
Remember that DOS pathnames are not case sensitive and can appear
in upper or lower case in the input file. If this concerns you, use
a version of sed which can ignore case when matching (gsed, ssed,
sedmod, sed16).
@echo off
:: sample MS-DOS batch file to alter path statements
:: requires GNU sed with the /i flag for s///
set old=C:\\SOME\\DOS\\PATH
set new=D:\\MY\\NEW\\PATH
gsed "s|%old%|%new%|gi" infile >outfile
:: or
:: sedmod -i "s|%old%|%new%|g" infile >outfile
set old=
set new=
Also, remember that under Windows long filenames may be stored in
two formats: e.g., as "C:\Program Files" or as "C:\PROGRA~1".