Windows 从文件中删除多行字符串
我试图在Windows中使用批处理从文件中删除多行字符串。我的批处理代码正在做一些奇怪的事情,例如将字符串Windows 从文件中删除多行字符串,windows,batch-file,Windows,Batch File,我试图在Windows中使用批处理从文件中删除多行字符串。我的批处理代码正在做一些奇怪的事情,例如将字符串ECHO置于关闭状态。在文件中 编辑:使用所有代码 如何让代码从文件中删除多行字符串 @echo off &setlocal enabledelayedexpansion Rem Read file and store all contents in string Set replace= Set target= Set infile=usermenuTest1.4d Rem %~
ECHO置于关闭状态。
在文件中
编辑:使用所有代码如何让代码从文件中删除多行字符串
@echo off &setlocal enabledelayedexpansion
Rem Read file and store all contents in string
Set replace=
Set target=
Set infile=usermenuTest1.4d
Rem %~1
Set outfile=usermenuTest2.4d
Rem %~2
for /f "delims=" %%i in (%infile%) do set "target=!target! %%i"
echo %target%
Rem Remove the target string from myOtherFile.txt: this code is from http://stackoverflow.com/questions/5273937/how-to-replace-substrings-in-windows-batch-file
@echo off & setlocal enabledelayedexpansion
for /f "tokens=1,* delims=¶" %%A in ( 'type "%outfile%"') do SET "string=%%A"
SET "modified=!string:%target%=%replace%!"
(echo(%modified%)>> "%outfile%"
我要替换的多行字符串示例:
Menu "User" {
Button "" {
Walk_Right ""
}
}
Menu "" {
// Button "CAD" {
// Walk_Right "CAD"
// }
Button "Design" {
Walk_Right "Design"
}
Button "Services" {
Walk_Right "Services"
}
Button "Strings" {
Walk_Right "Strings"
}
Button "Survey" {
Walk_Right "Survey"
}
Button "Utilities" {
Walk_Right "Utilities"
}
Button "Zoom" {
Walk_Right "Zoom"
}
}
试试这个:
@echo off & setlocal enabledelayedexpansion
for /f "tokens=1,* delims=¶" %%A in ( 'type "%outfile%"') do SET "string=%%A"
SET "modified=!string:%target%=%replace%!"
(echo(%modified%)>> "%outfile%"
发布您想要的多行示例字符串delete@ElektroHacker请参见编辑示例sortof的工作,
Echo已关闭
现在不存在,但我要删除的字符串仍然存在于文件中,而它不应该存在。我已使用显示所有变量的完整代码编辑了我的问题。for/f
循环逐行读取此内容。它不能将CR/LF
放入字符串变量。这是否意味着我可以使用此for循环/批处理代码替换文件中的多行字符串?文件中的每一行都是字符串。您可以使用以下代码显示该字符串:for/f“delims=“%%A in”(“键入“%outfile%”)do echo(%%A
)。for循环不会在字符串中放置“行尾”符号(CR/LF)。