Batch Sequential Processing of a List


By repetitively processing and stripping the first line in a list, the entire list can be processed. 

This is the "pure" way to use DOS to process an entire list. Very disk-intensive. Create a line fragment and put it at the head of your data file. The line fragment will be the name of your processing batch file followed by a single space. Now your data file is a batch file! After running it, you will have processed your first data line. Now run the data / batch file through FIND to strip off the first line, turning it back into a (smaller) data file again. Then add your line fragment again (turning it back into a batch file) and re-run it, this time processing the second line. Keep doing this until all lines are processed. As an example, suppose we start with this:
 

FRAGMENT.TXT
DATA.TXT
MAIN.BAT
PROCESS.BAT
PROCESS.BAT  data1 
data2 
data3
@echo off 
:START 
copy FRAGMENT.TXT + DATA.TXT DATA.BAT > NUL 
call DATA.BAT 
type DATA.BAT | find /v "PROCESS.BAT" > DATA.TXT 
copy DATA.TXT NUL | find "0" > NUL 
if errorlevel 1 goto START 
:DONE 
echo Processing %1
Here are the tricks in MAIN.BAT. First off, everything gets redirected into NUL to keep the screen clean. The initial COPY command will result in a DATA.BAT file that looks like this:
PROCESS.BAT data1
data2
data3
When DATA.BAT is CALLed, it will in turn run PROCESS.BAT, passing "data1" as the argument. PROCESS.BAT, in turn, will display "Processing data1" on the screen. Because DATA.BAT "runs" PROCESS.BAT (instead of CALLing it), control will *not* return to the second line of DATA.BAT after PROCESS.BAT finishes. Instead, control passes back to MAIN.BAT. Next, DATA.BAT is TYPEd through FIND to remove the first line. We now have a DATA.TXT without the first line:
data2
data3
By attempting to COPY DATA.TXT (into NUL, so there is no real copy happening), we can determine if all the lines have been processed. By a happy quirk, DOS will refuse to copy a zero-byte file. If that is the case, COPY will report "0 file(s) copied". By using FIND to search the output of COPY for that zero, we can determine if we are done with the file. If we don't find the zero, there are more lines left, so we go back to START.

Bad links? Questions? Send me mail.