本帖最后由 CrLf 于 2012-5-3 17:31 编辑
实现是很容易,但是这效率...- @echo off
- for /f "delims=" %%a in (a.txt) do (
- set str=%%a
- for /f "tokens=1* delims=#" %%b in (b.txt) do (
- if %%a==%%c set str=%%b#%%c
- )
- setlocal enabledelayedexpansion
- echo;!str!
- endlocal
- )
- pause
复制代码 另,如果 a.txt 内容不长,b.txt 中的替换前长于替换后,而且要替换的内容中不含 = ! ~ * " 这几个特殊字符的话,可以试试这样:- @echo off&setlocal enabledelayedexpansion
- for /f "delims=" %%a in (a.txt) do (
- set test=!str!
- set str=!str! "%%a"
- if !str!==!test! (
- set str=%%a
- for %%b in (!str!) do echo;%%~b
- )
- for /f "tokens=1* delims=#" %%b in (b.txt) do (
- set str=!str:%%c=%%b#%%c!
- )
- )
- for %%b in (!str!) do echo;%%~b
- pause
复制代码
|