In the following code
Set IP=%string:~0,15
REM Echo With spaces? "%string%"
Set IP=%IP: =%
REM Echo IP no spaces "%IP%" & pause
This seems to remove the spaces, but when SETLOCAL EnableDelayExpansion in the example below, while in a for loop
Set StorIP=%%B
Echo "!StorIP!"
Set StorIP=!StorIP: =!
Echo "!StorIP!"
Set %%B=!StorIP!
Echo %%B ^& "!StorIP!" & Pause
Set StorIP=!StorIP: =! seems to keep a space at the end in the IP address, so the IP would be "127.0.0.1 "
The code I currently have ...
setlocal enabledelayedexpansion
set filename=C:\Vision\etc
set outputfile=test.cfg
set log=C:\Vision\batlog
set equalsign=^=
Set CurrIDP=127.0.0.1
Set newIDP=192.168.1.1
For /f "tokens=1,2,3 delims=;=" %%A in (%filename%\system.cfg) do (
set hasoutput=0
Set StorIP=%%B
Echo "!StorIP!"
Set StorIP=!StorIP: =!
Echo "!StorIP!"
Set %%B=!StorIP!
Echo %%B ^& "!StorIP!" & Pause
If "%%B"=="%CurrIDP%" echo %%A!equalsign!%newIDP%;%%C;>>%outputfile% & set /a hasoutput+=1 & set /a nochg+=1 & Echo A:""%%A"" , B:""%%B"" , C:""%%C"" ^& errorlevel:%Errorlevel% Hasoutput:%hasoutput% - !hasoutput!>>%log%\testdrlog.log
If "!hasoutput!"=="0" echo %%A!equalsign!%%B;%%C>>%outputfile% & Echo A:""%%A"" , B:""%%B"" , C:""%%C"" ^& errorlevel:%Errorlevel% Hasoutput:%hasoutput% - !hasoutput!>>%log%\testdrlog.log
)
An example file
SERVER.DB=127.0.0.1 ; DB Files
SERVER.IMAGE=127.0.0.1 ; Images
SERVER.PARMS=127.0.0.1 ; Parms
SERVER.LOG=127.0.0.1 ; System Audit Logging
BRANCH.IMAGE=127.0.0.1 ; Branch Capture Server
SERVER.COMM=127.2.2.1 ; Communications Server
What I am trying to do is change an IP address in a file by re-writing the file into another. I think I'm close but can't seem to get ride of the extra white noise space in token %B. thanks for the help.