title: Reading data from a text file, comparing lines & displaying in preferred format
body: <p>I am reading a text file which contains the log in and out values of an employees,
  and trying to display in single line bot in and out values which are in different line for same employee and date.the data in that text file is as shown below.</p>
  
  <pre><code>line 1. 02,-"sangeetha-May 02, 2013 , -in-09:48:06:61
  line 2. 01,-"lohith-May 01, 2013 , -out-09:10:41:61
  line 3. 02,-"sushma-May 02, 2013 , -in-09:48:06:61
  line 4. 01,-"sushma-Jan 01, 2013 , -in-09:07:06:50-out-05:39:01:63
  line 5. 02,-"sangeetha-May 02, 2013 , -out-08:08:19:27
  line 6. 02,-"sushma-May 02, 2013 , -out-07:52:13:51
  line 7. 03,-"lohith-May 03, 2013 , -in-11:39:44:08
  </code></pre>
  
  <p>example: line 1 and line5 are in and out values for same employee sangeetha, so it should display like: </p>
  
  <pre><code>02,-"sangeetha-May 02, 2013 , -in-09:48:06:61, -out-08:08:19:27
  </code></pre>
  
  <p>Perhaps I am getting this output, but line 2, it don't have in value, so my code is not able to displaying that only which ever employee having both in and out values in different like its displaying those. I want to display theses records also with missing message appended to it..my code is this..</p>
  
  <pre><code>public class RecordParser {
    public static void main(String[] args) {
      RecordParser rp = new RecordParser();
      rp.recordFormatter("sample.txt");
    }
  
    public static void recordFormatter(String filename) {
  
      try {
        BufferedReader in;
        List&lt;String&gt; ls = new ArrayList&lt;String&gt;();
        String line = "";
        String line1;
        String line2;
        String lines;
        String mergedRecords = "";
        String normalRecords = "";
        String halfRecords = "";
        in = new BufferedReader(new FileReader(filename));
        while ((line = in.readLine()) != null) {
          ls.add(line);
        }
  
        for (int i = 0; i &lt; ls.size(); i++) {
          line1 = ls.get(i);
          if (line1.contains("in") &amp;&amp; line1.contains("out")) {
            normalRecords += line1;
            normalRecords += System.getProperty("line.separator");
            // ls.remove(i);
            // break;
          }
          for (int j = i + 1; j &lt; ls.size(); j++) {
            line2 = ls.get(j);
            if (line2.contains("in") &amp;&amp; line2.contains("out"))
              continue;
            if (line1.contains(getNameDate(line2))) {
              mergedRecords += line1
                  + line2.substring(line2.lastIndexOf(","), line2.length());
              mergedRecords += System.getProperty("line.separator");
              // ls.remove(i);
              // ls.remove(i);
              break;
            }
            if (!line1.contains(getNameDate(line2))) {
              if (!mergedRecords.contains(getNameDate(line1))) {
                halfRecords += line1;
                halfRecords += System.getProperty("line.separator");
              }
            }
          }
        }
        System.out.println(mergedRecords);
        System.out.println(normalRecords);
        System.out.println(halfRecords);
        // &amp;&amp; line2.contains("out") &amp;&amp; line1.contains("in")
      } catch (Exception e) {
        System.err.println(e.getMessage());
      }
    }
  
    public static String getNameDate(String input) {
      return input.substring(0, input.lastIndexOf(","));
    }
  }
  </code></pre>
  
  <p>Please can anybody modify it to show records which are having only either in entry or out entry?  </p>
  
  <p>For example..line 2 should display like: </p>
  
  <pre><code>line 2. 01,-"lohith-May 01, 2013 ,missing in, -out-09:10:41:61..
  </code></pre>
  
  <p>Presently I am getting output is:  </p>
  
  <pre><code>02,-"sangeetha-May 02, 2013 , -in-09:48:06:61, -out-08:08:19:27
  02,-"sushma-May 02, 2013 , -in-09:48:06:61-out-07:52:13:51
  01,-"sushma-Jan 01, 2013 , -in-09:07:06:50-out-05:39:01:63
  </code></pre>
  
  <p>I want that line 2 record to display with these.</p>