harding coding parameters in a batch file

Microsoft Access 2000
February 23, 2012 at 14:42:36
Specs: Windows XP
Hoping someone can help me modify the attached batch file. Currently, this batch file basically finds and replaces text within a file. Currently, parameters are passed at the command line
when executed. For example, if I want to find and replace the word
"Home" with "work" and save to a new file called TempA.txt, at the
command line, I type in:
FindReplace.bat "home" "work" >>TempA.txt

I need to modify this batch file so that there is no need to pass
the parameters. I want the parameters hardcoded in the logic below to always
find and replace "home" with "work" and always save it to a file
called TempA.txt This way, all I have to do is just type FindReplace.bat at
the command prompt.

Can someone help me modify the code below to hard code the find and replace
values within the batch file along with the NewFilename?
Any help is greatly appreciated.

@echo off


::syntax: FindReplace.bat OldStr NewStr >>NewFileName
:: OldStr [in] - string to be replaced
:: NewStr [in] - string to replace with
:: File [in] - file to be parsed

if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.

See More: harding coding parameters in a batch file

Report •

February 27, 2012 at 05:32:27
@echo off
set a=Home
set b=work
set file=TempA.txt

for /f "tokens=1,* delims=]" %%A in ('"type %file%|find /n /v """') do (
    set "line=%%B"
    if defined line (
        call echo.%%line:%a%=%b%%%
    ) ELSE echo.

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question