title: Count word occurences in very large file (memory exhausted on running) grep -o foo | wc -l
body: <p>What options are there for making word counts on very large files?</p>
  
  <p>I believe the whole file is on 1 line, which may be part of the problem as pointed out in one of the answers below.</p>
  
  <p>In this case, I have an xml file of 1.7 Gb and trying to count some things inside it quickly.</p>
  
  <p>I found this post 
  <a href="https://stackoverflow.com/questions/2908757/count-number-of-occurrences-of-a-pattern-in-a-file-even-on-same-line">Count number of occurrences of a pattern in a file (even on same line)</a>
  and the approach works for me up to a certain size. </p>
  
  <p>Up to 300Mb or so (40 000) occurrences was fine doing</p>
  
  <pre><code>cat file.xml | grep -o xmltag | wc -l    
  </code></pre>
  
  <p>but above that size, I get "memory exhausted".</p>