Wednesday, January 30, 2013

Find and Replace using Bat file

@echo off
setlocal enabledelayedexpansion
set INTEXTFILE=license.opt
set OUTTEXTFILE=license.txt
set SEARCHTEXT=172.19.32.166
set REPLACETEXT=hello
set OUTPUTLINE=

for /f "tokens=1,* delims=¶" %%A in ( '"type %INTEXTFILE%"') do (
SET string=%%A
SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!

echo !modified! >> %OUTTEXTFILE%
)
del %INTEXTFILE%
rename %OUTTEXTFILE% %INTEXTFILE%

No comments: