title: Linux shell awk: displaying different column values when condition met
body: <p>How can I use both conditional and loop statement inside the awk command to convert a file with special value to a different value like "Error", and not doing any subtraction, instead just display the converted new value like "Error" as the output? </p>
  
  <ol>
  <li><p>if none of the column value (except column 1 which stays the same in the final output) is equal to the special value like "11111", I use an awk command like following:</p>
  
  <pre><code>awk -F, '{print $1,$2,($3-$2),($4-$2),($5-$2),($6-$2),($7-$2),($8-$2),($9-$2),($10-$2),($11-$2),($12-$2),($13-$2),($14-$1)} ' all.cvs
  </code></pre></li>
  <li><p>if the column value = the special value, then no need to do "-$2", just display a new value like "Error"</p></li>
  </ol>
  
  <p>Basically I want: x means column value for column #2 to #14</p>
  
  <ul>
  <li><p>if $2 (column #2) = 11111</p>
  
  <pre><code>set $2="Error"
  </code></pre></li>
  <li><p>for $3 to $14 (column #3 to #14) if the column value is &lt;> 11111</p>
  
  <pre><code>$x=$x-$2 
  </code></pre></li>
  <li><p>if the column value =11111</p>
  
  <pre><code>$x=Error
  </code></pre></li>
  <li><p>At the end, the output will still show 14 columns including original #1 column value and converted/calculated new values for column #2 to #14 </p></li>
  </ul>
  
  <p>I have a file (all.cvs) like following: </p>
  
  <ul>
  <li><p>14 fields</p></li>
  <li><p>each line may contains a field with a value like "11111" (or any string value)</p></li>
  <li><p>each column separated by ","</p></li>
  <li><p>total number of lines is 90</p></li>
  </ul>
  
  <hr>
  
  <pre><code>$cat all.cvs
  
  A,11111,2,3,4,5,6,7,8,9,10,11,12,13 
  
  B,1,2,3,4,5,6,11111,8,9,10,11,12,13 
  
  C,1,2,3,4,5,6,7,8,9,11111,11,12,13 
  ....
  </code></pre>