Find and replace
Posted: 18 May 2012 02:11
hi,
I'm using the find and replace script as described on the site but i want the output piped directly to a file within the script and not on the command line and unsure where in the script to pipe it out. I have set the parameters within the script so am just calling the script name. ie.
@echo off
set file=c:\jobs\_IAT\20120512_ASAPRES_00007.txt
set newstr=0000007Advice
set oldstr=0000000Advice
::BatchSubstitude - parses a File line by line and replaces a substring"
::syntax: BatchSubstitude.bat OldStr NewStr File
:: OldStr [in] - string to be replaced
:: NewStr [in] - string to replace with
:: File [in] - file to be parsed
for /f "tokens=1,* delims=]" %%A in ('"type %file%|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%oldstr%=%newstr%%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)
Any direction would be appreciated.
Thanks
I'm using the find and replace script as described on the site but i want the output piped directly to a file within the script and not on the command line and unsure where in the script to pipe it out. I have set the parameters within the script so am just calling the script name. ie.
@echo off
set file=c:\jobs\_IAT\20120512_ASAPRES_00007.txt
set newstr=0000007Advice
set oldstr=0000000Advice
::BatchSubstitude - parses a File line by line and replaces a substring"
::syntax: BatchSubstitude.bat OldStr NewStr File
:: OldStr [in] - string to be replaced
:: NewStr [in] - string to replace with
:: File [in] - file to be parsed
for /f "tokens=1,* delims=]" %%A in ('"type %file%|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%oldstr%=%newstr%%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)
Any direction would be appreciated.
Thanks