 <p>Alternatively, if your implementation of <code>grep</code> supports it, you could use</p> <pre><code>grep -m 10 PATTERN FILE </code></pre> <p>Partial description from: <code>man grep</code> on Ubuntu 12.04</p> <pre><code>-m NUM, --max-count=NUM Stop reading a file after NUM matching lines. </code></pre> <p>This option was also available on my Red Hat 5.8 box where I was having a similar issue.</p>