title: Issues parsing textual data
body: <p>I have a text file that I want to parse and output to a csv. The data comes from SSURGO soil metadata (USDA). I have converted the pdf that describes the database tables, column names, and descriptions into a text file and would like to convert to a csv.</p>
  
  <p>The column values are:</p>
  
  <pre><code>Table Physical Name:
  Table Label:
  Column Physical name:
  Column Label:
  Desc:
  </code></pre>
  
  <p>Sometimes the Column physical name and column label do not include a description. Example input file is:</p>
  
  <pre><code>Table Physical Name: chaashto
  Table Label: Horizon AASHTO
  Column Physical Name: aashtocl 
  Column Label:   AASHTO
  desc: Some description here.
  </code></pre>
  
  <p>Not every column name and label has a corresponding desc: or Table Physical Name and Label.</p>
  
  <p>I have parsed the data to have one row for each column Physical Name and Label using the following code:</p>
  
  <pre><code>count = 0
  cnt = 0 
  out = open("output_test.txt", "wb")
  value1,value2,value3,value4,value5 = "","","","","" 
  for i,line in enumerate(lines):
  
      key, value = line.strip().split(':',1)
      if key == 'Table Physical Name':
          value1 = value.strip()
      if key == 'Table Label':
          value2 = value.strip()
      if key == 'Column Physical Name':
          value3 = value.strip()
      if key == 'Column Label':
          value4 = value.strip()
          if not lines[i+1].strip().startswith('desc'):
              count = 1
      if key == 'desc':
          value5 = value.strip()
          count = 1
      if count == 1:
          cnt += 1
          record = value1 + ";" +value2 + ";" + value3 + ";" + value4 + ";" + value5 +";\n"
          print cnt, record
          out.write(record)
          count = 0
          value3 = " "
          value4 = " "
          value5 = " "
      out.close()  
  </code></pre>
  
  <p>(Pardon the sloppy-looking code, just learning Python).</p>
  
  <p>At any rate, the issue is that sometimes when a line is output it does not include the Column Physical Name and inserts a \r at the end of the line. The subsequent line then includes the key "Column Physical Name: "Name of Column" </p>
  
  <p>This is how the output should look:</p>
  
  <pre><code>chfrags;Horizon Fragments;chfragskey;Chorizon Fragments Key;A non-connotative string of characters used to uniquely identify a record in the Horizon Fragments table.;
  </code></pre>
  
  <p>This is how the "bad" output looks:</p>
  
  <pre><code>coforprodo;Component Forest Productivity - Other; ;Low
  Column Physical Name: fprod_r; ;
  </code></pre>
  
  <p>In the above example, "fprod_r" should be between Other; and ";Low" and the "\r" after ;Low should not be there.</p>
  
  <p>The maddening thing is that when I subset the input file, the places where the errors occur no longer occur. So the code processes the text file correctly.</p>
  
  <p>Any help would be appreciated.</p>