I have a batch adapted from @MC ND, that search for a string and replace it in a given file.
It works well except that it deletes blank lines in my initial file.
@echo off
setlocal enableextensions disabledelayedexpansion
set "search=To_be_replaced"
set "replace=Well_Replaced"
set "File=TEST.txt"
for /f "delims=" %%i in ('type "%File%" ^& break ^> "%File%" ') do (
set "line=%%i"
setlocal enabledelayedexpansion
>>"%File%" echo(!line:%search%=%replace%!
endlocal
)
The input file is :
A
To_be_replaced
B
I expect the output to be:
A
Well_Replaced
B
The actual output is:
A
Well_Replaced
B
How can I manage to not delete blank lines ?