Using my superhuman Google powers (dripping with sarcasm LOL), the very first response for the search string of -- "batch read from two text files at the same time" -- gives...
It seems this EXACT same question was handled here a little over a year ago. (In fact the similarity makes me wonder if this is a homework question in some programming course?) It is an interesting question however. All credit of course goes to the participants in that discussion, with the main answers given by dbenham, with input from wmz.
There are three or four different methods proposed, two quite similar, but this is my favorite: (I made one slight change to meet your requirement that the content from the files are comma separated, and I used the Echo: construct.)
Use SET /P to read both files. FIND is used to get a count of the number of lines in file 1 because SET /P cannot tell the difference between a blank line and end of file.
This option eliminates a lot of limitations and complexity, but introduces its own limitations.
- Lines must use Windows style line terminators of <CR><LF>. Unix style <LF> will not work.
- lines are limited to 1021 bytes
- trailing control characters are stripped from each line.
This option is by far the fastest. It is preferred as long as the limitations are acceptable.
for /f %%N in ('type "%file1%"^|find /c /v ""') do set "cnt=%%N"
>"%out%" 9<"%file1%" <"%file2%" (
for /l %%N in (1 1 %cnt%) do (
<&9 set /p "ln1="
set /p "ln2="
On the off chance that this was some kind of assignment, or not, rather than just take this solution and say "Thank You", it would do you a lot of good to respond with a detailed explanation of exactly what is happening in this code as proof that you fully understand WHY it works. Understanding the why is the important thing and is what will allow you to apply this solution to future problems. You are also free to prefer an alternate solution, and if so, it would be interesting to see it and for you to tell us why you prefer it.
Cheers and Regards
Edited by bphlpt, 15 October 2013 - 02:37 AM.