我需要在文本文件中替换两行字符串。我编写了一个脚本来替换一个字符串:
@echo off
setlocal enabledelayedexpansion
rem file name
Set infile=file.txt
rem what to find
Set find=123
rem value to replace
Set replace=321
@echo off
setlocal enabledelayedexpansion
set COUNT=0
for /F "tokens=* delims=," %%n in (!infile!) do (
set LINE=%%n
set TMPR=!LINE:%find%=%replace%!
Echo !TMPR!>>tmp.txt
)
move tmp.txt %infile%
pause
如何修改它以一次替换两行?我的意思是将“查找”改为“替换”,将“查找2”改为“替换2”?
set TMPR=...
之后,添加set TMPR=!TMPR:%find2%=%replace2%!
。 - Stephan