I am creating a script which finds the old ip and replace with the new ip in a given input file. I have followed some examples from internet and i wrote the following script
@echo off&setlocal  
setlocal enabledelayedexpansion  
FOR /F "tokens=2 delims=:" %%f IN ('ipconfig ^| findstr /IC:"IPv4 Address"') DO 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=  
for /f "tokens=1,* delims=¶" %%A in ( '"findstr /n ^^ %textfile%"') do (
    SET string=%%A
    for /f "delims=: tokens=1,*" %%a in ("!string!") do set "string=%%b"
    if  "!string!" == "" (
        echo.>>%newfile%
    ) else (
        SET modified=!string:%search%=%replace%!
        echo !modified! >> %newfile%
    )
)  
del %textfile%  
rename %newfile% %textfile%  
)  
)  
endlocals
but i am not interested to create a new file and i need to modify the data in same file it self to avoid some error occurrences. could you please any one help me on this.