I am attempting to use a batch file to find an IP address in a .ini file in a given directory, and change it to a new address. I am suing this question as source.
The scripts runs without errors, however it creates replacement file that is empty and is also a .bat file, as opposed to a .ini.
Script:
set "file=M:\Haem\C.Mooney\cmooney\apex\Scripts\testIPCOnfig.ini"
:loop
findstr "^ipaddress=193.120.187.44$" "%file%" >nul || (
type "%file%" | repl "^ipaddress=193.120.187.44=.*" "ipaddress=193.120.187.110" >"%file%.tmp"
move "%file%.tmp" "%file%" >nul
)
ping -n 120 localhost >nul
goto :loop
The rpl command is taken form a helper file, sourced here.
The contents of the testIPCOnfig.ini file:
ipaddress=193.129.187.44
Appreciate any feedback.
UPDATED SCRIPT WITH UPDATED JREPL HELPER :
rem Check if the helper file is in same directory, if not exit
if not exist "%~dp0JREPL.bat" goto :EOF
rem if not exist "M:\Haem\C.Mooney\cmooney\apex\Scripts\IPChange\testIPCOnfig.txt" goto :EOF
rem call te helper JREPL>BAT to search for ipaddress and change it
call "%~dp0JREPL.bat" "^ipaddress=\d+\.\d+\.\d+\.\d+" "ipaddress=193.120.187.110" /F "M:\Haem\C.Mooney\cmooney\apex\Scripts\IPChange\testIPCOnfig.txt" /O -
Contents of the testIPCOnfig.txt:
ipaddress=193.120.187.44
Returns following Error:
JScript runtime error opening input file: File not found