 <p>Try using <code>GNU Parallel</code> like this... it will split <code>file.xml</code> into chunks of 1MB (or thereabouts on nearest new line) and pass each chunk to one CPU core to run <code>grep</code>, so not only should it work, but it should work faster too:</p> <pre><code>parallel --pipe grep -o xmltag &lt; file.xml | wc -l </code></pre>