title: really merge in .bat file
body: <p>How do I merge two text files in a .bat file?
  Or at least how to read the next line/test end of file in a .bat file?</p>
  
  <p>Is it possible to merge two text files using a .bat script?
  The idea is not to append, or concatenate but perform a merge operation based on the contents of each line. 
  A simplified example would be to to produce a sorted file from two sorted files, like in the pseudo code (pseudo as I can’t seem to find a way to <em>read the next line</em> and test the end of the file read – outside a for loop)</p>
  
  <pre><code>:TOP
   Set /p  Line1 Read_Line (file1)
  :set /p  Line2 Read_Line (file2)
  :TEST
   IF EOF(file1) GOTO  FINISH2
   IF EOF (file2) GOTO FINISH1
   IF  %Line1%  &lt; %Line2% 
          (echo %Line1% - not in 2 &gt;&gt; File3
          set  /p Line1 =Read_Line (file1)
          GOTO TEST)
  ELSE IF %Line1%  &gt; %Line2% 
          (echo %Line2% - not in 1&gt;&gt; File3
          set  /p Line2=Read_Line (file2)
          GOTO TEST)
  ELSE echo %Line1% in both &gt;&gt; File3
  GOTO TOP
  :FINISH1
  echo %Line2% - not in 1&gt;&gt; File3
          set /p Line1=Read_Line (file1)
          IF NOT (EOF (File1)) 
                  (echo %Line1% - not in 2 &gt;&gt; File3
                   GOTO FINISH1)
  ELSE GOTO EOF
  :FINISH2
             echo %Line2% - not in 1&gt;&gt; File3
          set /p Line2 =Read_Line (file2)
          IF NOT (EOF (File1) )
                  (echo %Line2% - not in 1 &gt;&gt; File3
                   GOTO FINISH2)
  </code></pre>
  
  <p>I tried with for loops, but branching inside loops seems to stop the loop. I tried various things (including a parallel .bat) to find a way to move the cursor inside the file using <code>set</code>  and <code>&lt;</code> but can’t find how to do it right.</p>