read 2 text files and write to the 3rd one

I have 2 text files:

TextFile1.txt contains only one entry
TextFile2.txt contains multiple entries, unknown number

I would like a script (I am open to the most feasible suggestions) that will write in TextFile3.txt as follows:

TextFile_1_Entry1 TextFile2_Entry_1
TextFile_1_Entry1 TextFile2_Entry_2
TextFile_1_Entry1 TextFile2_Entry_3
TextFile_1_Entry1 TextFile2_Entry_4
.
.
.
.
TextFile_1_Entry1 TextFile2_Entry_n

Basically, in excell this can be done with the following function:
=PROPER(A21&" "&B21)

I am looking for a batch script or other form of script that I could execute in the folder which contains TextFile1 and TextFile2 , a scrip that will write the output in TextFile3 by default.

Thank you!
BarbulescuAsked:
Who is Participating?
 
Saqib Husain, SyedEngineerCommented:
Try this macro

Sub combine1n2()
Open "D:\Documents and Settings\Saqib\My Documents\Downloads\Temp\Temp\TextFile1.txt" For Input As #1
Input #1, prefix
Close 1
Open "D:\Documents and Settings\Saqib\My Documents\Downloads\Temp\Temp\TextFile2.txt" For Input As #1
suffix = Input(LOF(1), 1)
suffix = Split(suffix, vbCrLf)
Close 1
For i = 0 To UBound(suffix)
suffix(i) = prefix & " " & suffix(i)
Next i
Open "D:\Documents and Settings\Saqib\My Documents\Downloads\Temp\Temp\output.txt" For Output As #1
suffix = Join(suffix, vbCrLf)
Print #1, suffix
Close 1
End Sub
0
 
Saqib Husain, SyedEngineerCommented:
Can you upload two sample text files? The files should closely represent the actual data.
0
 
BarbulescuAuthor Commented:
Hi

Attached you can find the sample files.

Thank you!
Temp.zip
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
ScriptAddictCommented:
If you need a VBS or powershell script let me know.
0
 
Bill PrewCommented:
Here's a BAT approach that should work.

@echo off
if exist "output.txt" del "output.txt"
for /F "usebackq tokens=*" %%A in ("textfile1.txt") do (
  for /F "usebackq tokens=*" %%B in ("textfile2.txt") do (
    echo %%A %%B>>"output.txt"
  )
)

Open in new window

~bp
0
 
ScriptAddictCommented:
Wow, so simple,  I had kind of written batch files off a while ago.  

Perhaps they are worth a second look.
0
 
Bill PrewCommented:
Yes, they can be quite powerful once you get some of the basic building blocks down.

~bp
0
 
BarbulescuAuthor Commented:
Thank you for your support.
0
 
Bill PrewCommented:
Welcome, glad that was useful, thanks for the feedback.

~bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.