• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Match two .csv files and merge

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question too difficult for “beginning”. Moving discussion.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic