title: Find line to change in text file by conditions for lines before it
body: <p>Is there a way in python to find and change a line in a text file for which the lines above it fulfill certain conditions? In particular consider a text file that looks like this:</p>
  
  <pre><code>dimensions      [0 1 -1 0 0 0 0];
  
  internalField   uniform (0 0 0);
  
  boundaryField
  {
      inlet
      {
          type            fixedValue;
          value           uniform (0 0.6 0); 
      }
      outlet
      {
          type            inletOutlet;
          inletValue      uniform (0 0 0);
          value           uniform (0 0 0);
      }
  }
  </code></pre>
  
  <p>In this file I would for example like to change the line that contains <code>value           uniform (0 0.6 0);</code>. The condition would be that it is the line that is inside <code>boundaryField</code> and inside <code>inlet</code> and begins (after stripping leading spaces) with <code>value</code>.</p>
  
  <p>What is the best way to get the line index of this line to change it?</p>