批处理文件:如何替换” = QUOT; (等号)和一个字符串变量? [英] Batch file: How to replace "=" (equal signs) and a string variable?
问题描述
此外SED,怎么能一个等号被取代?
以及如何使用一个字符串变量中的字符串替换?
考虑这个例子:
FOR / F令牌= *%% B IN(test.txt的)DO(
SETLOCAL ENABLEDELAYEDEXPANSION
SET T =是
SET老= %%乙
设置新老=:T =!
ECHO!新的! ENDLOCAL
)::设置新老=!==!
两个问题:
首先,我不能使用变量%T%!=!
设定t =是
SET老= %%乙
设置新老=:T =!
第二,我不能代替等号,在命令行
设置新老=!==!
为什么不使用艾林?我无法找到一种方法用一个初始文件并没有从艾林错误,要做到这一点,只是忽略了他们NUL :.
Strangly,类型%0包括整个文件,即使有=和!之间的文件字符的结尾,就用它运行不会以同样的方式后,该批处理文件类型。
@ECHO OFF
GOTO跳跃
1,1r =!
Ë
:跳跃SET新老== =============ECHO%新的%GT; %TEMP%\\ var.tmp
TYPE%0> %TEMP%\\ edlin.tmpEDLIN%TEMP%\\ var.tmp< %TEMP%\\ edlin.tmp> NUL:SET / p编辑新建=<%TEMP%\\ VAR.TMP
ECHO%编辑新建%ERASE%TEMP%\\ VAR.TMP
ERASE%TEMP%\\ VAR.BAK
ERASE%TEMP%\\ edlin.tmp
Besides SED, how can an equal sign be replaced? And how can I use a string variable in string replacement?
Consider this example:
For /F "tokens=*" %%B IN (test.txt) DO (
SETLOCAL ENABLEDELAYEDEXPANSION
SET t=is
SET old=%%B
SET new=!old:t=!
ECHO !new!
ENDLOCAL
)
:: SET new=!old:==!
Two problems:
First, I cannot use the variable %t% in !:=!.
SET t=is
SET old=%%B
SET new=!old:t=!
Second, I cannot replace the equal sign in the command line
SET new=!old:==!
Why not use Edlin? I could not find a way to do this with one initial file and no errors from Edlin, but just ignore them with NUL:. Strangly, the TYPE %0 includes the whole file even if there's an end of file character between the = and !, using TYPE on the batch file after it has run will not work the same way.
@ECHO OFF
GOTO skip
1,1r=!
e
:skip
SET "new==old============="
ECHO %new% > %TEMP%\var.tmp
TYPE %0 > %TEMP%\edlin.tmp
EDLIN %TEMP%\var.tmp < %TEMP%\edlin.tmp > NUL:
SET /P newnew=<%TEMP%\VAR.TMP
ECHO %newnew%
ERASE %TEMP%\VAR.TMP
ERASE %TEMP%\VAR.BAK
ERASE %TEMP%\edlin.tmp
这篇关于批处理文件:如何替换&rdquo; = QUOT; (等号)和一个字符串变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!