 <pre><code>$ cat file [foo] name = 3 name = 17 [bar] name = 24 name = 5 $ awk -v id="foo" '/\[/{f=index($0,"["id"]")} f' file [foo] name = 3 name = 17 $ awk -v id="bar" '/\[/{f=index($0,"["id"]")} f' file [bar] name = 24 name = 5 </code></pre> <p>The above just sets a flag (<code>f</code> for found) when it finds a line containing <code>[foo]</code>, for example, and clears it when it finds the next line containing a <code>[</code>. When <code>f</code> is set it prints the line.</p> <p>Note also that unlike any possible sed solution, the above will be unaffected by RE metacharacters or delimiter characters in the search variable (e.g. <code>., ?, *, +, /, (, etc.</code>) since it is looking for a STRING not a regular expression.</p>