I have a text file called NonProd.txt containing a server name on each line, i.e.
c123abc
c234abc
c345abc
cfcd123
etc.
I also have a batch file (given below) which reads each line from the text file, extracts 3 characters from each line, and holds that value in variable. I then want to use the variable to replace the XXX characters in the mypath variable.
The code below works in reading the text file, extracting the server names and extracting the 3 characters it needs, but I cannot get the string substitution to work, i.e. replace XXX in mypath with the 3 characters extracted.
Can anyone advise?
@echo off
SET mypath=C:\XXX\SYS\exe\folder\folder\
FOR /F %%X IN (NonProd.txt) DO (
echo ServerName = %%X
Call Set "SID=%%X"
Call Set "SID=%%SID:~1,3%%"
Call Echo SID = %%SID%%
ECHO mypath = %mypath%
CALL set mypath=%mypath:XXX=%SID%%
ECHO newpath = %mypath%
ECHO.
)
@echo Completed.
pause
CALL set mypath=%%mypath:XXX=!SID!%%and alsocall ECHO newpath = %%mypath%%CALL CALL set mypath=%%%%mypath:XXX=%%SID%%%%%%