Convert a column from textfile into set using Scala
<p>I am trying to convert one set column from multiple files into Set. I am getting the result but it seems that this code considers the whole column from each file as one set element and hence does not remove any duplicates. </p>

<p>I think I am not able to convert or vectorize individual elements from one file so it is grouping the column as single element.</p>

<pre><code>import scala.io.Source


if (args.length &gt; 0){

var ids : Set[String] = collection.immutable.HashSet()
    for (arg&lt;-args){
ids += Source.fromFile(arg).getLines().filterNot(_.trim.startsWith("#")).map(_.split("\t")(0)).mkString("\n")
}
println(ids)
}

else
Console.err.println("Please enter filename")
</code></pre>

<p>Input files</p>

<p>**File a:</p>

<pre><code>#df
ABC 2
ABC 7
CVF 9
</code></pre>

<p>**File b:</p>

<pre><code>#dsdff
#
#
ABC 1
DFG 2
CVF 3
</code></pre>

<p>What I get is this output </p>

<pre><code>Set(ABC
DFG
CVF, ABC
ABC
CVF)
</code></pre>

<p>Desired output:</p>

<pre><code>Set(ABC,DFG,CVF)
</code></pre>