Recently, I needed to create a function that could replace a specific line of a text file, so I searched some things up on the internet, found some code on this website and altered it:
>%tempfile% (
for /f "tokens=* delims= " %%a in (%file%) do (
set /a line+=1
if "%%a" == "%line2%" (ECHO %line3%) ELSE ECHO %%a
)
)
The code works perfectly fine, except for the fact that whenever I use it, it removes all lines in-between paragraphs in my text files. Example: Let's say I have the following information in my text file:
Mango
Apple
Peach
Pear
Upon using this code to perhaps change "Apple" to "Plum", the following will be put into the "%tempfile%" which later is renamed to look like the original file:
Mango
Plum
Peach
Pear
Could I rewrite the code in a way that the space between "Apple" and "Peach" remains after "Apple" changes to "Plum"? (Like this:)
Mango
Plum
Peach
Pear