@echo off & setlocal enableextensions
for /f "tokens=*" %%f in ("C:\_D\TEST\My File 1.txt") do set myfile1_=%%~sf
for /f "tokens=*" %%f in ("C:\_D\TEST\My File 2.txt") do set myfile2_=%%~sf
CONCAT %myfile1_% %myfile2_% /B2
endlocal & goto :EOF
The output will be
C:\_M>c:\_d\test\cmdfaq
My File 1.txt Line 1 My File 2.txt Line 1
My File 1.txt Line 2 My File 2.txt Line 2
My File 1.txt Line 3 My File 2.txt Line 3
My File 1.txt Line 4 My File 2.txt Line 4
My File 1.txt Line 5
@echo off & setlocal enableextensions
set myfile1_=C:\_D\TEST\My File 1.txt
set myfile2_=C:\_D\TEST\My File 2.txt
if not exist "%myfile1_%" (
echo Exiting: File "%myfile1_%" not found
goto :EOF)
if not exist "%myfile2_%" (
echo Exiting: File "%myfile2_%" not found
goto :EOF)
::
:: Build a Visual Basic Script
set skip=
set vbs_=%temp%\tmp$$$.vbs
findstr "'%skip%VBS" "%~f0" > "%vbs_%"
::
:: Run the VBS script with Microsoft Windows Script Host Version 5.6
cscript //nologo "%vbs_%" "%myfile2_%" "%myfile1_%"
::
:: Clean up
for %%f in ("%vbs_%") do if exist "%%~f" del "%%~f"
endlocal & goto :EOF
'
'................................................................
'The Visual Basic Script
'
Const ForReading = 1, ForWriting = 2, ForAppending = 8 'VBS
Dim fso, arg, f1, f2, line1, line2 'VBS
Set fso = CreateObject("Scripting.FileSystemObject") 'VBS
Set arg = WScript.Arguments 'VBS
Set f1 = fso.OpenTextFile(arg(0), ForReading) 'VBS
Set f2 = fso.OpenTextFile(arg(1), ForReading) 'VBS
Do While (Not f1.AtEndOfStream) Or (Not f2.AtEndOfStream) 'VBS
line1 =
" " 'VBS
If Not f1.AtEndOfStream Then 'VBS
line1 = f1.ReadLine 'VBS
End If 'VBS
line2 = "" 'VBS
If Not f2.AtEndOfStream Then 'VBS
line2 = f2.ReadLine 'VBS
End If 'VBS
WScript.Echo line1 &
" " & line2 'VBS
Loop 'VBS
The output will be
C:\_D\TEST>cmdfaq
My File 2.txt Line 1 My File 1.txt Line 1
My File 2.txt Line 2 My File 1.txt Line 2
My File 2.txt Line 3 My File 1.txt Line 3
My File 2.txt Line 4 My File 1.txt Line 4
My File 1.txt Line 5
Now what if you wish to start the first file at the third, not the
first line? Better than trying to adjust the methods above, is first
separately to filter the first two lines from the first file to an
auxiliary file. For example see the method given in
.