windows - How do I include quotes in the command inside the quotes of FOR /F -
this works fine.
/f "delims=" %%g in ('tagread.exe %%l genre') ( echo %gg )
but when add sed
command ('...') fails
/f "delims=" %%g in ( 'tagread.exe %%l genre ^| sed -e ''/curtain^|exit^|spacer/^^!s~.*~dance~'' ' ) ( echo %%g)
output:
sed: newline or end of file found in pattern
edit: despite loopless command succeeds:
tagread.exe c:\temp\1.wma genre | sed -e '/curtain^|exit^|spacer/^!s~.*~dance~'
how sed command , quotes accepted in (...) quotes?
edit: dbenham said: "the single quote never needs escaped when used /f. outer single quotes delimit command string, , inner single quotes work fine."
here's solution:
for /f "delims=" %%g in ( 'tagread.exe %%l genre ^| sed -e '/curtain^|exit^|spacer/^^!s~.*~dance~'' ) ( echo %%g)
it fails:
the syntax of command incorrect.
edit: here simplified , stand-alone version regarding problem:
for /f "delims=" %%g in ( 'echo xxx ^| sed -e '/yyy/^^!s~.*~zzz~'' ) ( echo %%g)
succeeds:
zzz
this:
echo xxx | sed -e '/yyy^|uuu/^!s~.*~zzz~'
succeeds:
zzz
this:
for /f "delims=" %%g in ( 'echo xxx ^| sed -e ''/yyy^|uuu/^^!s~.*~zzz~''' ) ( echo %%g)
fails:
'uuu' not recognized internal or external command, operable program or batch file.
----------- solution -----------
the cause of failure wasn't quotes. was insufficiently escaped ^. dbenham's 1), minimum fix is:
for /f "delims=" %%g in ( 'tagread.exe %%l genre ^| sed -e ''/curtain^^^|exit^^^|spacer/^^!s~.*~dance~'' ' ) ( echo %%g)
and simplified version:
for /f "delims=" %%g in ( 'echo xxx ^| sed -e ''/yyy^^^|uuu/^^!s~.*~zzz~''' ) ( echo %%g)
one may remove redundant ' :
for /f "delims=" %%g in ( 'tagread.exe %%l genre ^| sed -e '/curtain^^^|exit^^^|spacer/^^!s~.*~dance~' ' ) ( echo %%g)
and
for /f "delims=" %%g in ( 'echo xxx ^| sed -e '/yyy^^^|uuu/^^!s~.*~zzz~'' ) ( echo %%g)
edit: solution in instance simpler still:
for /f "delims=" %%g in ('echo "xxx^^^|ppp" ^| find "x^^^|p"') ( echo %%g)
for /f runs command via new cmd.exe process.
for example:
for /f %%a in ('echo hello') echo %%a
for /f runs command using:
c:\windows\system32\cmd.exe /c echo hello
at time of posting, desired command has still not been posted in question. let assume correct operating command following (it makes no sense me)
tagread.exe c:\temp\1.wma genre | sed -e '/curtain^|exit^|spacer/^^!s~.*~dance~'
you want put command in /f loop.
you have 2 options.
1) can escape poison characters pass through cmd.exe command properly:
for /f "delims=" %%g in ('tagread.exe c:\temp\1.wma genre ^| sed -e '/curtain^^^|exit^^^|spacer/^^!s~.*~dance~'') echo %%g
i guessing had !
escaped ^^!
because have delayed expansion enabled. new cmd.exe process have delayed expansion disabled, not need additional escaping construct.
2) or can use fact cmd.exe strips outer double quotes when /c command used. need add double quotes :-)
for /f "delims=" %%g in ('"tagread.exe c:\temp\1.wma genre | sed -e '/curtain^|exit^|spacer/^!s~.*~dance~'"') echo %%g
in case, ^
must removed before !
because of how delayed expansion works: quoted escaped !
= "^!"
, , unquoted = ^^!
of course, of above contingent on whether original command (without loop) valid. looks suspect me. regardless, concepts above work working command put /f loop.
Comments
Post a Comment