BASH - Change information in columns 2 by 2 using for loop and If statements
<p>I have the following tab-separated file:</p>

<pre><code>A1    A1    0       0       1       1       0 0     0 0     2 2     1 2
A2    A2    0       0       1       1       1 1     1 1     0 0     1 2
A3    A3    0       0       1       2       1 1     1 1     0 0     2 2
A4    A4    0       0       1       1       1 1     0 0     0 0     1 2
</code></pre>

<p>The idea is to modify the information between column 7 (included) and the end in the way that, for every row, if column 7 and 8:</p>

<ul>
<li><p>equal “0 0”: don’t modify</p></li>
<li><p>equal “1 1”: don’t modify</p></li>
<li><p><strong>equal “1 2” or “2 1”: change to “2 2”</strong></p></li>
<li><p>equal “2 2”: don’t modify </p></li>
</ul>

<p>And the same for the following columns (9 and 10, then 11 and 12, 13 and 14, and so on..).</p>

<p>I started to extract the columns I want to work on using the command:</p>

<blockquote>
  <p>awk '{for (i = 7; i &lt;= NF; i++) printf $i " "; print ""}' test.ped > tmp_test.txt</p>
</blockquote>

<p>Then I was thinking to use a for loop with If statements, with this general format:</p>

<pre><code>for i between 7 and the end (for (i = 7; i &lt;= NF)):
    if i and i+1 == “1 2”:
        replace by “2 2”
    elif i and i+1 == “2 1”:
        replace by “2 2”
    else
        pass
    i=i+2 (increase i to do the same for the next double columns)
</code></pre>

<p>But I am stuck here. Is the general format logical or is there a faster way to do the same? Am I going in the right direction? </p>

<p>The expected output (after merging the first 6 columns from the initial file and the ones that I subsetted and modified) is:</p>

<pre><code>A1    A1    0       0       1       1       0 0     0 0     2 2     2 2
A2    A2    0       0       1       1       1 1     1 1     0 0     2 2
A3    A3    0       0       1       2       1 1     1 1     0 0     2 2
A4    A4    0       0       1       1       1 1     0 0     0 0     2 2
</code></pre>

<p>Thank you for your help!</p>