windows - how to create a batch script for replacing the string in a file with out creating a new file for output -
i creating script finds old ip , replace new ip in given input file. have followed examples internet , wrote following script
@echo off&setlocal setlocal enabledelayedexpansion /f "tokens=2 delims=:" %%f in ('ipconfig ^| findstr /ic:"ipv4 address"') set ip=%%f set ip1=%ip:~1% echo %ip1% set "search=old ip" set "replace=new ip" set "textfile=sample.txt" set "newfile=output.txt" set outputline= /f "tokens=1,* delims=¶" %%a in ( '"findstr /n ^^ %textfile%"') ( set string=%%a /f "delims=: tokens=1,*" %%a in ("!string!") set "string=%%b" if "!string!" == "" ( echo.>>%newfile% ) else ( set modified=!string:%search%=%replace%! echo !modified! >> %newfile% ) ) del %textfile% rename %newfile% %textfile% ) ) endlocals
but not interested create new file , need modify data in same file self avoid error occurrences. please 1 me on this.
Comments
Post a Comment