• Post Reply Bookmark Topic Watch Topic
  • New Topic

Match two .csv files and merge  RSS feed

 
Pedro Rod
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I need help. The situation is, I have two .csv files (Main.csv and File1.csv). The Main.csv contains all the needed lines (one column only), as below:
Column1=
air.com.magnetjoy.android.myhomegp
at.ner.lepsWorld3Plus
bloodpressuremonitor.bpcalculator.pro.advanced
e8e2e280b01548653e5e7d80b97b066
5969ef00dc29bf7d087985d36b9greed4e4

Meanwhile in File1.csv contains (consists one column as well)=
Column 1
at.ner.lepsWorld3Plus
bloodpressuremonitor.bpcalculator.pro.advanced
5969ef00dc29bf7d087985d36b9greed4e4

So, I need to create another .csv (Main_Edit) with all the list in Main.csv and match line with File1.csv. If the line of File1.csv is listed in complete list in Main.csv, label it as 1(in column 2), otherwise, label it as 0(in column 2). So, I need to create another csv file (Main_Edit.csv), as listed below=
Column 1 Column 2
air.com.magnetjoy.android.myhomegp 0
at.ner.lepsWorld3Plus 1
bloodpressuremonitor.bpcalculator.pro.advanced 1
e8e2e280b01548653e5e7d80b97b066 0
5969ef00dc29bf7d087985d36b9greed4e4 1

The image of desired Main_Edit.csv is attached here.

My code is here=


I am stuck in if condition statements there. Please help me.
Thanks for your kind attention.
Main_Edit.png
[Thumbnail for Main_Edit.png]
 
Carey Brown
Saloon Keeper
Posts: 3312
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't mentioned if the files are sorted in a particular order. If you're viewing the files through Excel I'm assuming that the number of lines is reasonable. Given that, I'd load the entire Main.csv into a List, then load the entire File1.csv into a HashSet. Then iterate through the List and look up the item in the HashSet to see if it's there.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Need to think how you are going to reproduce the main file. As you mentioned, that file contains all necessary data, so its might worth to make a copy of it, rather than build a new file line by line.
2. Then open the file with less data, and check, is entry present in a file "main_copy". If it is a case, label main_copy particular line with 1.
3. Maybe all lines need to label with zeros at start, and only matches override with 1's. Or find the matches, and then go thru the rest of the lines and label with zeros.

Pedro Rod wrote://if condition goes here, need help here

It doesn't seem that you have a clear understanding, what you want/have to do.

I'd suggest you to write down the clear steps on a plain paper, what has to be done. Then you would find it much easier to translate it to code.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question too difficult for “beginning”. Moving discussion.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!