【发布时间】:2015-01-14 11:08:15
【问题描述】:
我正在寻找一种使用 Windows 批处理脚本在文本文件中查找和替换多个单词的方法。
我知道可以用这个 bat 脚本替换一个单词:
@echo off &setlocal
set "search=%1"
set "replace=%2"
set "textfile=Input.txt"
set "newfile=Output.txt"
(for /f "delims=" %%i in (%textfile%) do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
echo(!line!
endlocal
))>"%newfile%"
del %textfile%
rename %newfile% %textfile%
现在,我只需要更进一步,输入搜索并替换另一个文件中类似于这种格式的字符串:
search_string1, replace_string1
search_string2, replace_string2
search_string3, replace_string3
.
.
.
我认为我会以某种方式逐行处理文件,并将它们解析为两个变量(搜索、替换),然后将其输入到上面的脚本中。有什么想法吗?我是 Windows 批处理脚本的新手,以前从未真正做过,所以请注意我的新手问题。
【问题讨论】:
标签: windows batch-file replace find