@echo off
for /f "delims=[]" %%n in ('find /n "REM DATA:" "%~dpnx0"') do set /a n=%%n
more +%n% "%~dpnx0">myNew.bat
REM rest or your batchfile
goto :eof
REM DATA:
@echo off
echo this is your new batchfile
echo on computer %computername%
REM etc.
the for
just gets the line number where your new content is stored (start of DATA section), the more
command writes that content to a new file (in fact "the currently running batchfile, skipping the first n lines").
The code after REM DATA:
isn't processed by the parser (just copied by more
), so no escaping needed.
Note: more
converts TABs to (several) spaces.