DOS file name escaped for use with * nix commands

I want to avoid the DOS file name, 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

(Note: %~f1- extends %1to the full path name - C:\utils\MyFile.txt)

I found that the backslash in %FILENAME%just eludes the next letter.

How can I double them so that they are shielded?

(I have cygwin installed, so feel free to use any other * nix commands)

Decision

Combining the suggestions of Jeremy and Alexandra Week and using | for the separator 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
+3
source share
3 answers

. , BAT set var = `cmd`, unix. , , , Some Pattern .

set FILENAME=%~f1
echo s/Some Pattern/%FILENAME%/ | sed -e "s/\\/\\\\/g" >sedcmd.tmp
sed -f sedcmd.tmp inputfile
del /q sedcmd.tmp

[]: , . , . sed http://sourceforge.net/projects/unxutils cmd.exe bat.

+2

( )...

> cygpath -m c:\some\path
c:/some/path

, .

+2

@ , . upvotes

@Jeremy

, :

sed: -e # 1, char 8: unterminated `s

, , . ( )

Update: Ok, I tried it with UnixUtils and it worked. (For reference, the UnixUtils I downloaded was dated March 1, 2007 and uses GNU sed version 3.02, my Cygwin installation has GNU sed version 4.1.5)

0
source

Source: https://habr.com/ru/post/1696595/


All Articles