title: Parse a very large text file with Python?
body: <p>So, the file has about 57,000 book titles, author names and a ETEXT No. I am trying to parse the file to only get the ETEXT NOs</p>
  
  <p>The File is like this:</p>
  
  <pre><code>TITLE and AUTHOR                                                     ETEXT NO.
  
  Aspects of plant life; with special reference to the British flora,      56900
   by Robert Lloyd Praeger
  
  The Vicar of Morwenstow, by Sabine Baring-Gould                          56899
   [Subtitle: Being a Life of Robert Stephen Hawker, M.A.]
  
  Raamatun tutkisteluja IV, mennessä Charles T. Russell                    56898
   [Subtitle: Harmagedonin taistelu]
   [Language: Finnish]
  
  Raamatun tutkisteluja III, mennessä Charles T. Russell                   56897
   [Subtitle: Tulkoon valtakuntasi]
   [Language: Finnish]
  
  Tom Thatcher's Fortune, by Horatio Alger, Jr.                            56896
  
  A Yankee Flier in the Far East, by Al Avery                              56895
   and George Rutherford Montgomery
   [Illustrator: Paul Laune]
  
  Nancy Brandon's Mystery, by Lillian Garis                                56894
  
  Nervous Ills, by Boris Sidis                                             56893
   [Subtitle: Their Cause and Cure]
  
  Pensées sans langage, par Francis Picabia                                56892
   [Language: French]
  
  Helon's Pilgrimage to Jerusalem, Volume 2 of 2, by Frederick Strauss     56891
   [Subtitle: A picture of Judaism, in the century
    which preceded the advent of our Savior]
  
  Fra Tommaso Campanella, Vol. 1, di Luigi Amabile                         56890
   [Subtitle: la sua congiura, i suoi processi e la sua pazzia]
   [Language: Italian]
  
  The Blue Star, by Fletcher Pratt                                         56889
  
  Importanza e risultati degli incrociamenti in avicoltura,                56888
   di Teodoro Pascal
   [Language: Italian]
  </code></pre>
  
  <p>And this is what I tried:</p>
  
  <pre><code>def search_by_etext():
  
      fhand = open('GUTINDEX.ALL')
      print("Search by ETEXT:")
  
      for line in fhand:
          if not line.startswith(" [") and not line.startswith("~"):
              if not line.startswith(" ") and not line.startswith("TITLE"):
                      words = line.rstrip()
                      words = line.lstrip()
                      words = words[-7:]
                      print (words)
  
  
  search_by_etext()
  </code></pre>
  
  <p>Well the code mostly works. However for some lines it gives me part of title or other things. Like:
  This kind of output(), containing 'decott' which is a part of author name and shouldn't be here.
  <img src="https://i.stack.imgur.com/Zi8Eh.png" alt="This kind of output"><a href="https://i.stack.imgur.com/Zi8Eh.png" rel="nofollow noreferrer">2</a></p>
  
  <p>For this:
  The Bashful Earthquake, by Oliver Herford                                56765
   [Subtitle: and Other Fables and Verses]</p>
  
  <p>The House of Orchids and Other Poems, by George Sterling                 56764</p>
  
  <p>North Italian Folk, by Alice Vansittart Strettel Carr                    56763
   and Randolph Caldecott
   [Subtitle: Sketches of Town and Country Life]</p>
  
  <p>Wild Life in New Zealand. Part 1, Mammalia, by George M. Thomson         56762
   [Subtitle: New Zealand Board of Science and Art, Manual No. 2]</p>
  
  <p>Universal Brotherhood, Volume 13, No. 10, January 1899, by Various       56761</p>
  
  <p>De drie steden: Lourdes, door Émile Zola                                 56760
   [Language: Dutch]</p>
  
  <p>Another example:</p>
  
  <p><img src="https://i.stack.imgur.com/PQAKv.png" alt=""><a href="https://i.stack.imgur.com/PQAKv.png" rel="nofollow noreferrer">4</a></p>
  
  <p>For 
  Rhandensche Jongens, door Jan Lens                                       56702
   [Illustrator: Tjeerd Bottema]
   [Language: Dutch]</p>
  
  <p>The Story of The Woman's Party, by Inez Haynes Irwin                     56701</p>
  
  <p>Mormon Doctrine Plain and Simple, by Charles W. Penrose                  56700
   [Subtitle: Or Leaves from the Tree of Life]</p>
  
  <p>The Stone Axe of Burkamukk, by Mary Grant Bruce                          56699
   [Illustrator: J. Macfarlane]</p>
  
  <p>The Latter-Day Prophet, by George Q. Cannon                              56698
   [Subtitle: History of Joseph Smith Written for Young People]</p>
  
  <p>Here: Life] shouldn't be there. Lines starting with blank space has been parsed out with this:</p>
  
  <pre><code>if not line.startswith(" [") and not line.startswith("~"):
  </code></pre>
  
  <p>But Still I am getting those off values in my output results. </p>