title: count occurances of each word in apache spark
body: <pre><code>  val sc = new SparkContext("local[4]", "wc")
  
    val lines: RDD[String] = sc.textFile("/tmp/inputs/*")
    val errors = lines.filter(line =&gt; line.contains("ERROR"))
  
    // Count all the errors
    println(errors.count())
  </code></pre>
  
  <p>the above snippet would count the number of lines that contain the word ERROR. Is there a simplified function similar to "contains" that would return me the number of occurrences of the word instead?</p>
  
  <p>say the file is in terms of Gigs and i would want to parallalize the effort using spark clusters.</p>