title: Grepping second pattern after matching first pattern
body: <p>Is there any grep/sed option which will allow me to match a pattern after matching another pattern? For example: Input file (<code>foo</code>s are variable patterns starting with <code>0</code> mixed with random numbers preceded by <code>#</code> in front):</p>
  
  <pre><code>0foo1  
  0foo2  
  0foo3  
  \#89888  
  0foo4  
  0foo5  
  \#98980  
   0foo6
  </code></pre>
  
  <p>So once I try to search for a variable pattern (eg. <code>foo2</code>), I also want to match another pattern (eg, <code>#number</code>) from this pattern line number, in this case, <code>#89888</code>.</p>
  
  <p>Therefore output for variable <code>foo2</code> must be:</p>
  
  <pre><code>foo2  #89888
  </code></pre>
  
  <p>For variable <code>foo5</code>:</p>
  
  <pre><code>foo5  #98980
  </code></pre>
  
  <p><code>foo</code>s consist of every character, including which may be considered metacharacters.</p>
  
  <p>I tried a basic regex match script using tcl which will first search for <code>foo*</code> and then search for next immediate <code>#</code>, but since I am working with a very large file, it will take days to finish. Any help is appreciated.</p>