Five Stars

Merge two text files, row by row, to create one new column

Good day guys

I am having difficulty with a specific use case in Talend. I have simplified my problem a bit below:

I have two text files, one contains a list of names like so:

John

Peter

Sandra

 

The second file contains a list of surnames like so:

Williams

Alkema

Smith

 

The 2 files will always have the same number of records.

 

I need to join these 2 files together, line by line, like so:

John Williams

Peter Alkema

Sandra Smith

 

In Java this is rather straight forward. One can read the names into and array, and then the surnames into an array, and loop through them like so:

for (int i = 0; i < name_array.length(); i++)

{

   System.out.println (name_array[i] + " " + surname_array[i]);

}

 

But how can I do this in Talend? I need to write the combined string out to a file again.

 

Thank you

2 ACCEPTED SOLUTIONS

Accepted Solutions
Twelve Stars TRF
Twelve Stars

Re: Merge two text files, row by row, to create one new column

Here a solution:

Capture.PNG

 

Capture.PNG

tMap to add a sequence (you 2 with the same model):

Capture.PNG

tMap to join the records:

Capture.PNG

 


TRF
Five Stars

Re: Merge two text files, row by row, to create one new column

Hi there

 

I got around to testing the solution and it is working great.

 

I subsequently moved away from files and used a hashmap, and things are looking good!

6 REPLIES
Four Stars

Re: Merge two text files, row by row, to create one new column

If you simply want to join them sequentially, you could add a sequence to each input (using tMap) and then use a third tMap to join them on sequence.

Twelve Stars TRF
Twelve Stars

Re: Merge two text files, row by row, to create one new column

Here a solution:

Capture.PNG

 

Capture.PNG

tMap to add a sequence (you 2 with the same model):

Capture.PNG

tMap to join the records:

Capture.PNG

 


TRF
Five Stars

Re: Merge two text files, row by row, to create one new column

Thank you to you both. You guys are too awesome! And thank you for building the job for me with screenshots, I really appreciate it.

 

I am back at work on Thursday and will try it out. I will let you guys know how it goes. 

Twelve Stars TRF
Twelve Stars

Re: Merge two text files, row by row, to create one new column

@necrolingus, did you test the proposed solution?

TRF
Five Stars

Re: Merge two text files, row by row, to create one new column

Hi there

 

I got around to testing the solution and it is working great.

 

I subsequently moved away from files and used a hashmap, and things are looking good!

Twelve Stars TRF
Twelve Stars

Re: Merge two text files, row by row, to create one new column

Great!

TRF