I want to escape a DOS filename so I can use it with sed. I have a DOS batch file something like this:
set FILENAME=%~f1 sed 's/Some Pattern/%FILENAME%/' inputfile
%~f1 - expands
%1 to a Fully qualified path name -
I found that the backslashes in
%FILENAME% are just escaping the next letter.
How can I double them up so that they are escaped?
(I have cygwin installed so feel free to use any other *nix commands)
Combining Jeremy and Alexandru Nedelcu's suggestions, and using | for the delimiter in the sed command I have
set FILENAME=%~f1 cygpath "s|Some Pattern|%FILENAME%|" >sedcmd.tmp sed -f sedcmd.tmp inputfile del /q sedcmd.tmp