|Actually, this is quite difficult, if not impossible, using native batch, unless a third-party process is involved (a stream editor or something like it, which is actually doing all the work). This is because FOR unconditionally removes blank lines, even ones with spaces or tabs. I would recommend either qbasic, which is extremely simple to work with at this level, or vbscript, or visual basic. Here's a bare-bones vbscript:|
do while not xin.atendofstream
if x="" then x="new data replacing blank lines"
'end of script
to run the script, you need to have cscript.exe available, and use it like this (where your saved vbscript is called noblanks.vbs)::
cscript /nologo noblanks.vbs <rawfile.txt >newfile.txt
If you want to dis-allow lines that are all space, use rtrim(x) in line 5:
You can streamline the commandline by dropping the cscript command into a batchfile: @echo off & cscript /nologo <%1 >%2
or use batch prompting for input and output files if you want more safety.
here's a qbasic snippet in case you're inclined that way:
INPUT "SOURCE FILE: ", INFIL$
OPEN INFIL$ FOR INPUT AS #1
DO WHILE NOT EOF(1)
LINE INPUT #1, K$
IF LTRIM$(K$) = "" THEN K$ = "NEW DATA REPLACES BLANK LINES"