批处理文件查找包含子字符串并分配给变量的字符串

时间:2013-07-26 23:50:04

标签: batch-file

我正在尝试创建一个批处理文件,该文件将在文件中查找字符串并将其替换为新值。

代表

test.txt包含几行,其中包含以下文本,其中YYYYMMDD可以不同:

"location":"/test/update_20130723/update_20130723.txt"
"/test/update_20130723/update_20130724.txt",
"/test/update_20130723/update_20130725.txt"

我希望批处理文件更新test.txt,其中“update_ *”更新为“update_20130726”

这是我的test.bat:

set newFilename="/test/update_20130726/update_20130726.txt"

for /f "tokens=* delims= " %%a in (test.txt) do (
set str=%%a
set str=!str:"update_*/update_*.txt"=%newFilename%!
echo !str!>> newfile
)

当我尝试运行此代码时,没有任何内容更新test.txt。

提前致谢。

1 个答案:

答案 0 :(得分:0)

使用repl:

添加命令

repl.bat也可以在这里找到 - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855

type "test.txt" | repl "(update_........)" "update_20130726" m >"file.txt"