1
我需要刪除文件中可能出現的字符串。該字符串有很多行。 我可以使用批處理腳本執行此操作嗎?商店多行字符串在批次變量
我聽說你不能有在批量多行變量?該字符串將來自另一個文件,我將使用批處理讀入一個變量。
下面的代碼似乎只存儲字符串的文件的第一個/最後一行?發生什麼事了?
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%
)
您可以使用輔助批處理文件與'/ v開關findrepl.bat',並通過指定的起點和終點方面從文件中刪除文本塊。 – foxidrive 2014-01-31 07:45:28