title: bash loop through file replace string
body: <p>I have a file called file.txt that contains the following:</p>
  
  <pre><code>123
  223
  Lane,id,s_id_sample_id
  1,3_range.single_try,N76
  2,44_range.single_try,N77
  3,92_out_range.double_try,N79
  </code></pre>
  
  <p>I like to loop through this file and do the following:</p>
  
  <blockquote>
    <p>begin from line after 'Lane' then split using comma and take the second column (id)
       then take the id column and split on underscore, then
        search and replace all dots and underscores with 'X' EXCEPT THE LAST TWO UNDERSCORES. So do not search and replace the last underscore (e.g. double_try).</p>
  </blockquote>
  
  <p>So will like to end up with:</p>
  
  <pre><code>123
  223
  Lane,id,s_id_sample_id
  1,3Xrange_single_try,N76
  2,44Xrange_single_try,N77
  3,92XoutXrange_double_try,N79
  </code></pre>
  
  <p>This is what I have done:</p>
  
  <pre><code>while IFS=',' read -r f1 f2; do
   sed -e 's/_/X/g;s/\./X/g;s/'
   echo "$f1,$f2"
   done &lt; "$file" &gt; output
  mv output $file
  </code></pre>
  
  <p>The problem is how can I specify to ignore the last two underscores?</p>