Help for loop replace string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
king558
Posts: 1
Joined: 02 Jun 2019 01:39

Help for loop replace string

#1 Post by king558 » 02 Jun 2019 02:19

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.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Help for loop replace string

#2 Post by aGerman » 02 Jun 2019 13:39

Use
echo(!line!
instead of
echo !line!

Steffen

Post Reply