我需要删除文件中可能出现的字符串。字符串有很多行。我可以使用批处理脚本执行此操作吗?
我听说你不能在批处理中拥有多于一行的变量?该字符串将来自另一个文件,我将使用 Batch 将其读入变量。
以下代码似乎只将文件的第一行/最后一行存储在字符串中?怎么了?
Rem Read file and store all contents in string
Set replace=
Set target=
Set OUTFILE=res.txt
for /f "delims=" %%i in (myFile.txt) do set target=%target% %%i
echo %target%
Rem When I print target I only have one line not many lines?? Whats going wrong
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
for /f "tokens=1,* delims=¶" %%A in ( '"type myOtherFile.txt"') do (
SET string=%%A
SET modified=!string:%target%=%replace%!
echo !modified! >> %OUTFILE%
)