title: awk for loop with if else conditions to array
body: <p>I seek your help in storing awk returning values in an array for my awk for loop using if else conditions.</p>
  
  <pre><code>If  $3 == $7
  then print $9 multiplied by $4
  else print $4 multiplied by (2 minus $9)
  </code></pre>
  
  <p>I got this working so far by:</p>
  
  <pre><code>awk '{if ($3 == $7) print $9*$4; else print $4*(2-$9);}' file &gt;outfile
  </code></pre>
  
  <p>the above code works for the first data column (<code>$9</code>). However, I want to loop through all columns from 9 to 1547 and return an array containing the returning values. This should be simple enough but I cant seem to understand some basic concepts here. </p>
  
  <p>So far I understand the need to declare the number of loops, before the actual function, by:</p>
  
  <blockquote>
    <p>awk ' {for(i=9;i&lt;=NF;i++)} END {if ($3 == $7) print $i*$4; else print $4*(2-$i);}'</p>
  </blockquote>
  
  <p>However, how and when to declare the array is beyond me (biologist). Any help would be highly appreciated.</p>
  
  <p>Example:</p>
  
  <p>input (big file.. here column 1-10):</p>
  
  <blockquote>
    <p>rs2070501 22 A 0.0206 0.337855 rs2070501 G A 0.977 0.066</p>
  </blockquote>
  
  <p>output:</p>
  
  <blockquote>
    <p>0.0210738</p>
  </blockquote>
  
  <p>here the else statement kicks in ($3 * (2-$9)</p>
  
  <p>How to get awk to print out the array 9-Nth, and not just column 9</p>