954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

merge two csv files

Hi,
I m trying to write code to merge two csv files. could any one help me out to get the hints to start?

javausers
Newbie Poster
21 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Not enough info. Merge by concatenation, by joining records in input order, by joining based on a key value present in both files? Etc?
Formats or examples of both files, and how are they to be merged (or an example output file) would be really helpful here.

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

I'm sorry for that.
Here are the example files,
1st file looks like:
sno,first name,last name
1,xx,yy
2,aa,bb

2nd file looks like:
sno,place
1,pp
2,qq

Output:
sno,first name,last name,place
1,xx,yy,pp
2,aa,bb,qq

javausers
Newbie Poster
21 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

OK, no problemo.
Are you looking for a quick'n'dirty way or a good Java object-oriented way?

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

for time being I need a quick way

javausers
Newbie Poster
21 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Read each file into a map (2 files, 2 maps) by extracting the sno to use as key, and put the rest of the line as the value.
When you have the two maps look through all the keys in the first map, and get the corresponding values from both maps. For each key concatenate the key with both values and write that to the output file.

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

I'm sorry, I m very beginner. Could u explain more plz :-(

javausers
Newbie Poster
21 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: