title: Parsing unstructured text in Python
body: <p>I wanted to parse a text file that contains unstructured text. I need to get the address, date of birth, name, sex, and ID.</p>
  
  <pre><code>. 55 MORILLO ZONE VIII,
  BARANGAY ZONE VIII
  (POB.), LUISIANA, LAGROS
  F
  01/16/1952
  ALOMO, TERESITA CABALLES
  3412-00000-A1652TCA2
  12    
  . 22 FABRICANTE ST. ZONE
  VIII LUISIANA LAGROS,
  BARANGAY ZONE VIII
  (POB.), LUISIANA, LAGROS
  M
  10/14/1967
  AMURAO, CALIXTO MANALO13
  </code></pre>
  
  <p>In the example above, the first 3 lines is the address, the line with just an "F" is the sex, the DOB would be the line after "F", name after the DOB, the ID after the name, and the no. 12 under the ID is the index/record no.</p>
  
  <p>However, the format is not consistent. In the second group, the address is 4 lines instead of 3 and the index/record no. is appended after the name (if the person doesn't have an ID field).</p>
  
  <p>I wanted to rewrite the text into the following format:</p>
  
  <pre><code>name, ID, address, sex, DOB
  </code></pre>