title: How to grep lines between two patterns in a big file with python
body: <p>I have a very big file, like this:</p>
  
  <pre>
  [PATTERN1]
  line1
  line2
  line3 
  ...
  ...
  [END PATTERN]
  [PATTERN2]
  line1 
  line2
  ...
  ...
  [END PATTERN]
  </pre>
  
  <p>I need to extract in another file, lines between a variable starter pattern [PATTERN1] and another define pattern [END PATTERN], only for some specific starter pattern. <br> For example:</p>
  
  <pre>[PATTERN2]
  line1 
  line2
  ...
  ...
  [END PATTERN]
  </pre>
  
  <p>I already do the same thing, with a smaller file, using this code:</p>
  
  <pre><code>FILE=open('myfile').readlines()
  
  newfile=[]
  for n in name_list:
      A = FILE[[s for s,name in enumerate(FILE) if n in name][0]:]
      B = A[:[e+1 for e,end in enumerate(A) if 'END PATTERN' in end][0]]
      newfile.append(B)
  </code></pre>
  
  <p>Where 'name_list' is a list with the specific starter patterns that I need. <br></p>
  
  <p>It works!! but I suppose there is a better way to do this working with big files, without using the .readlines() command. <br>
  Anyone can help me? <br></p>
  
  <p>thanks a lot!</p>