Talend Connect
Virtual Summit
JOIN US!
And visit the Customer
& Community Lounge.
May 27-28, wherever you are.

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

Highlighted
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


Accepted Solutions
Highlighted
Sixteen Stars
Sixteen 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

View solution in original post

Highlighted
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!

View solution in original post


All Replies
Highlighted
Five 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.

Highlighted
Sixteen Stars
Sixteen 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

View solution in original post

Highlighted
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. 

Highlighted
Sixteen Stars
Sixteen Stars

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

@necrolingus, did you test the proposed solution?

TRF
Highlighted
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!

View solution in original post

Highlighted
Sixteen Stars
Sixteen Stars

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

Great!

TRF

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog