[Edited question to try and make clearer]
Simple one, i think....
I am trying to use the following batch code to replace a string in a text file;
@echo off
set "replace=#user=guest"
set "replaced=user=StoreUser1"
set "source=C:\Users\adam\Desktop\test.txt"
set "target=C:\Users\adam\Desktop\test1.txt"
setlocal enableDelayedExpansion
(
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" %source%') do (
set "line=%%b"
if defined line set "line=!line:%replace%=%replaced%!"
echo(!line!
)
) > %target%
endlocal
Its not executing as expected, it simply leaves the text unchanged. If however I modify the SET commands (and of course the text in the text file) as;
set "replace=#userguest"
set "replaced=userStoreUser1"
Then this works as expected. I'm assuming the second '=' which is required is causing the SET not to function correctly and needs escaped somehow.
Hope that makes sense and thanks in advance!
Adam