2010-09-19 188 views
0

这就是我需要的。使用DOS查找并替换批处理文件

比方说有TEMP.TXT 比方说TEMP.TXT有以下内容的文件:

[email protected] 
[email protected] 
[email protected] 

我的批处理文件create.bat应该问三个参数作为来自用户的输入, ,然后用相应的值替换temp.txt。

说。

Pls enter your name:Tom 
Tom - Confirm Y/N: Y 
<<now anywhere the temp.txt says @name, it is replace by Tom>> 

请帮我写一个脚本吗?

谢谢, Naveen。

回答

0
rem @echo off 

setlocal enabledelayedexpansion enableextensions 

rem Don't use the same file name for both here 
set InputFile=temp.txt 
set OutputFile=temp2.txt 

call :ask name name 
call :ask age age 
call :ask "e-Mail address" email 

del %OutputFile% 1>nul 2>&1 
for /f "delims=" %%l in (%InputFile%) do (
    set Line=%%l 
    set Line=!Line:@name=%name%! 
    set Line=!Line:@age=%age%! 
    set Line=!Line:@email=%email%! 
    >>%OutputFile% echo.!Line! 
) 

goto :eof 

rem :ask "placeholder title" variable_name 
:ask 
set /p %2=Please enter your %~1: 
choice /M "!%2! - Confirm" 
if errorlevel 2 goto ask 
goto :eof 
相关问题