I have written a simple script which will find and replace a matching string. I am getting issue in the output file. Following is my script
@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=1 delims=" %%a in ('FINDSTR "^applicationPort" "E:\BATCH-SCRIPTING\Version.txt"') do (
echo Installed version is %%a
set oldPort=%%a
)
for /f "tokens=1 delims=" %%b in ('FINDSTR "^applicationPort" "E:\BATCH-SCRIPTING\Sample.txt"') do (
echo Installed version is %%b
set newPort=%%b
)
set SEARCHTEXT="applicationPort=8080"
set REPLACETEXT="applicationPort=8090"
set file="E:\BATCH-SCRIPTING\Sample.txt"
for /f "tokens=1,* delims=]" %%A in ('"type %file% |find /n /v """') do (
set "line=%%B"
if defined line (
call echo %%line:%SEARCHTEXT%=%REPLACETEXT%%%>> %file%_new
) ELSE echo.
)
move /Y %file%_new %file% > nul
In my output file the expected output should be : applicationPort=8090
, but i am getting 8080=applicationPort=8090=8080
.
Can anyone help me in resolving this issue.