How to write a line only once in a text file
<p>I have two text files <code>bala.txt</code> and <code>bala1.txt</code></p>

<p><code>bala.txt</code> contains text line by line as</p>

<pre><code>balamurugan,rajendran,chendurpandian
christopher
updateba
</code></pre>

<p><code>bala1.txt</code> contains text line by line as</p>

<pre><code> ba
</code></pre>

<p>Here i need to check <code>bala1.txt</code> with <code>bala.txt</code> and write into a log file as</p>

<pre><code>Pattern Name:ba
LineNo : 1 : balamurugan,rajendran,chendurpandian
LineNo : 3 : updateba
</code></pre>

<p>now its writing like this</p>

<pre><code> Pattern Name :ba
LineNo : 1 : balamurugan,rajendran,chendurpandian
LineNo : 2 : christopher
Pattern Name :ba
LineNo : 3 : updateba
</code></pre>

<p>Here is my code</p>

<pre><code>while ((line = file.ReadLine()) != null)
                                    {
              if (line.IndexOf(line2,StringComparison.CurrentCultureIgnoreCase) != -1)
                    dest.WriteLine("Pattern Name :" + line2);
                    dest.WriteLine("LineNo : " + counter.ToString() + " : " + line);
                                        counter++;
                                    }
                                    file.BaseStream.Seek(0, SeekOrigin.Begin);
                                        //(0, SeekOrigin.Begin);
                                    counter = 1;
</code></pre>

<p>I dont know how to write pattern name ba only once...Any suggestion??</p>
