I have a file called file.txt that contains the following:
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
I like to loop through this file and do the following:
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).
So will like to end up with:
123
223
Lane,id,s_id_sample_id
1,3Xrange_single_try,N76
2,44Xrange_single_try,N77
3,92XoutXrange_double_try,N79
This is what I have done:
while IFS=',' read -r f1 f2; do
sed -e 's/_/X/g;s/\./X/g;s/'
echo "$f1,$f2"
done < "$file" > output
mv output $file
The problem is how can I specify to ignore the last two underscores?