title: Merge the intersection of two CSV files with Scala
body: <p>From input 1: </p>
  
  <pre><code>fruit, apple, cider  
  animal, beef, burger
  </code></pre>
  
  <p>and input 2: </p>
  
  <pre><code>animal, beef, 5kg
  fruit, apple, 2liter
  fish, tuna, 1kg
  </code></pre>
  
  <p>I need to produce:</p>
  
  <pre><code>fruit, apple, cider, 2liter
  animal, beef, burger, 5kg
  </code></pre>
  
  <p>The closest example I could get is:  </p>
  
  <pre><code>object FileMerger {
  def main(args : Array[String]) {
    import scala.io._
    val f1 = (Source fromFile "file1.csv" getLines) map (_.split(", *")(1))
    val f2 = Source fromFile "file2.csv" getLines
    val out = new java.io.FileWriter("output.csv")
    f1 zip f2 foreach { x =&gt; out.write(x._1 + ", " + x._2 + "\n") }
    out.close
    }
  }
  </code></pre>
  
  <p>The problem is that the example assumes that the two CSV files contain the same number of elements and in the same order. My merged result must only contain elements that are in the first and the second file. I am new to Scala, and any help will be greatly appreciated.</p>