SET string=bath Abath Bbath XYZbathABC SET modified=%string:bath=hello% ECHO %string% ECHO %modified%
EDIT
At first, it wasnβt visible that you needed the replacement to be preceded by reading a line from a file.
Well, with a batch file you have few options for working with files. In this particular case, you will need to read the line, perform a replacement, then output the modified line, and then ... What then? If you need to replace all the "baths" in the entire file, you will have to use a loop:
@ECHO OFF SETLOCAL DISABLEDELAYEDEXPANSION FOR /F %%L IN (file.txt) DO ( SET "line=%%L" SETLOCAL ENABLEDELAYEDEXPANSION ECHO !line:bath=hello! ENDLOCAL ) ENDLOCAL
You can add a redirect to the file:
ECHO !line:bath=hello!>>file2.txt
Or you can apply the redirection to the batch file. It must be a different file.
EDIT 2
Added the correct switch of slow expansion for the correct processing of some characters that have special meaning with the syntax of a batch script, for example ! , ^ et al. (Thanks jeb !)
Andriy M Mar 11 2018-11-11T00: 00Z
source share