title: Compare Two CSV Files and Fetch Data
body: <p>I have two csv files. One Master <em>CSV File around 500000 records</em>. Another <em>DailyCSV file has 50000 Records</em>. </p>
  
  <p>The DailyCSV files misses few columns which has to be fetched from Master CSV File.</p>
  
  <p>For example</p>
  
  <p>DailyCSV File</p>
  
  <pre><code>id,name,city,zip,occupation
  1,Jhon,Florida,50069,Accountant
  </code></pre>
  
  <p>MasterCSV File</p>
  
  <pre><code>id,name,city,zip,occupation,company,exp,salary
  1, Jhon, Florida, 50069, Accountant, AuditFirm, 3, $5000
  </code></pre>
  
  <p>What I have to do is, read both files, match the records with <code>ID</code>, if <code>ID</code> is present in the master file, then i have to fetch <code>company, exp, salary</code> and write it to a new csv file.</p>
  
  <p>How to achieve this.??</p>
  
  <p>What I have done Currently</p>
  
  <pre><code> while (true) {
              line = bstream.readLine();
              lineMaster = bstreamMaster.readLine();
  
              if (line == null || lineMaster == null)
              {
                  break;
              }
              else
              {
                  while(lineMaster != null)
                  readlineSplit = line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)", -1);
                  String splitId = readlineSplit[4];
                   String[] readLineSplitMaster =lineMaster.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)", -1);
                    String SplitIDMaster = readLineSplitMaster[13];
                    System.out.println(splitId + "|" + SplitIDMaster);
                    //System.out.println(splitId.equalsIgnoreCase(SplitIDMaster));
                    if (splitId.equalsIgnoreCase(SplitIDMaster)) {
  
                        String writeLine = readlineSplit[0] + "," + readlineSplit[1] + "," + readlineSplit[2] + "," + readlineSplit[3] + "," + readlineSplit[4] + "," + readlineSplit[5] + "," + readLineSplitMaster[15]+ "," + readLineSplitMaster[16] + "," + readLineSplitMaster[17];
                        System.out.println(writeLine);
                        pstream.print(writeLine + "\r\n");
                    }
              }
  
          }pstream.close();
          fout.flush();
          bstream.close();
          bstreamMaster.close();
  </code></pre>