How to REALLY merge files in a .bat

[Closed]
Report
-
How to REALLY merge two text files in a .bat ?
Or at least how to read the next line / test end of file in a .bat ?

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 `read the next line' and test the end of the file read - outside a for loop)


: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% < %Line2%
(echo %Line1% - not in 2 >> File3
set /p Line1 =Read_Line (file1)
GOTO TEST)
ELSE IF %Line1% > %Line2%
(echo %Line2% - not in 1>> File3
set /p Line2=Read_Line (file2)
GOTO TEST)
ELSE echo %Line1% in both >> File3
GOTO TOP
:FINISH1
echo %Line2% - not in 1>> File3
set /p Line1=Read_Line (file1)
IF NOT (EOF (File1))
(echo %Line1% - not in 2 >> File3
GOTO FINISH1)
ELSE GOTO EOF
:FINISH2
echo %Line2% - not in 1>> File3
set /p Line2 =Read_Line (file2)
IF NOT (EOF (File1) )
(echo %Line2% - not in 1 >> File3
GOTO FINISH2)

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 "set" and "<" but can't find how to do it right.