If we can assume that the number of lines in both files is equal, this will work:
@ECHO OFF
TYPE NUL>output.txt
SETLOCAL ENABLEDELAYEDEXPANSION
SET linecount=0
FOR /F %%i IN (file1.txt) DO SET /a linecount=!linecount!+1
FOR /L %%n IN (1,1,!linecount!) DO (
FOR /f "tokens=1* delims=:" %%a in ('findstr /n .* "file1.txt"') DO (
IF "%%a"=="%%n" SET lineA=%%b
)
FOR /f "tokens=1* delims=:" %%a in ('findstr /n .* "file2.txt"') DO (
IF "%%a"=="%%n" SET lineB=%%b
)
ECHO !lineA! >> output.txt
ECHO !lineB! >> output.txt
)
The first FOR loop simply count the lines in file1.txt. The second loop iterates over the number of lines. Both internal loops execute the command findstr /n .* "fileX.txt"
on file1.txt and file2.txt. The /n parameter outputs the content of the file adding : at the beginning of each line. So we split each modified line with delimeter :
and store everything after :
if the line starts with the current line index which is incremented after each interation. So after n-th iteration of the "big" loop !lineA!
contains contains the n-th line of the first file and !lineB!
contains the n-th line of the second file and both lines are appended to output.txt.