Page 1 of 1

Help for loop replace string

Posted: 02 Jun 2019 02:19
by king558
This is my test.tmp file

Code: Select all

TEMPLATE = Test

Test = \
    Test1 \
    Test2
This is my copy.bat file

Code: Select all

@echo off

set oldText1=Test1 \
set oldText2=Test2
set newText1=newTest
set newText2=

setlocal enableDelayedExpansion
for /F "tokens=1* delims=]" %%j in ('type "Test.tmp" ^| find /V /N ""') do (
	if "%%k"=="" (
		echo.
	) else (
		set "line=%%k"
		set "line=!line:%oldText1%=%newText1%!"
		set "line=!line:%oldText2%=%newText2%!"
		if not !line!==[] echo !line!
	)
)
endlocal
Output is

Code: Select all

TEMPLATE = Test

Test = \
    newTest
ECHO is off.
Problem is the line ECHO is off. It must not appear, how can I solve it? Please help me out of this trouble.

Re: Help for loop replace string

Posted: 02 Jun 2019 13:39
by aGerman
Use
echo(!line!
instead of
echo !line!

Steffen