The following code is assumed to replace the col3 substring in the variable dir with the value of the variable var in every iteration, but it fails to do so. Does anyone know what is wrong with this code?
code:
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET dir=col1 col2 col3 col4 col5 col6 col7 col8
FOR /L %%i IN (1,1,5) DO (
SET var=v%%i
SET dir=!dir:col3=%var%!
ECHO !dir!
)
PAUSE
output:
col1 col2 col4 col5 col6 col7 col8
col1 col2 col4 col5 col6 col7 col8
col1 col2 col4 col5 col6 col7 col8
col1 col2 col4 col5 col6 col7 col8
col1 col2 col4 col5 col6 col7 col8
desired output:
col1 col2 v1 col4 col5 col6 col7 col8
col1 col2 v2 col4 col5 col6 col7 col8
col1 col2 v3 col4 col5 col6 col7 col8
col1 col2 v4 col4 col5 col6 col7 col8
col1 col2 v5 col4 col5 col6 col7 col8
for %%V in (!var!) do SET "dir=!dir:col3=%%V!"