You may show several lines with just one echo
command:
@echo off
setlocal EnableDelayedExpansion
set NL=^
%Don't remove%
%these lines%
(
echo ^
Line one!NL!^
Line two!NL!^
Line three
) > test.txt
EDIT: After read this additional specification in a comment:
It's a large block of more batch code, maybe 50 lines...
I may want to edit this code later on, so ease of reading is a necessity.
I don't want to have all 50 lines in one line, as this is for clarity rather than functionality.
I think I finally understood the request, that is: "How to embeed lines of text in a Batch file, and extract them to another file?". This is the method I use for the same purpose:
@echo off
rem Use :GetResource subroutine to extract text placed in this file; for example:
call :GetResource example.bat
call :GetResource example.txt
rem Execute the just extracted Batch file
call example.bat
goto :EOF
A couple examples of embedded files
<resource id="example.bat">
@echo off
echo Hello, I am example.bat
type example.txt
</resource>
<resource id="example.txt">
An example of data file
</resource>
rem Extract text from lines placed in a "resource" in this .bat file
:getResource resourceId
setlocal EnableDelayedExpansion
rem Resource data start format: <resource id="resourceId">
set start=
set lines=
for /F "tokens=1,3 delims=:=>" %%a in ('findstr /N "^</*resource" "%~F0"') do (
if not defined start (
if "%1" equ "%%~b" set start=%%a
) else (
if not defined lines set /A lines=%%a-start-1
)
)
set line=0
(for /F "skip=%start% tokens=1* delims=]" %%a in ('find /N /V "" ^< "%~F0"') do (
setlocal DisableDelayedExpansion
echo(%%b
endlocal
set /A line+=1
if !line! equ %lines% exit /B
)) > "%~1"
exit /B