 <p>In case (a), What do you expect to happen if the pattern occurs within the 10 lines?</p> <p>Anyway, here are some awk scripts which should work (untested, though; I don't have Solaris):</p> <pre><code># pattern plus 10 lines awk 'n{--n;print}/PATTERN/{if(n==0)print;n=10}' # between two patterns awk '/PATTERN1/,/PATTERN2/{print}' </code></pre> <p>The second one can also be done similarly with <code>sed</code></p>