I am trying to create a copy of a text file by changing a single specific line that matches a pattern. I wrote the batch script below which works fine except it creates the output without the blank lines (CRLF) in the original. I tried to explicitly echo blank lines with code like if "x!line!"=="x" echo.>>output.txt
to no avail.
for /f "tokens=* delims=" %%s in ('type input.txt ^| find /v "" ') do (
if "!line:~0,21!"=="specific_pattern" (
echo this_new_line_instead>> output.txt
) else (
echo !line!>> output.txt
How to preserve the blank lines in the original file?