Hi Folks
I have tried awk command to conditionally add or subtract value from specific row in a file. The test file looks like:
# cat test.txt
cont x y
Max 0.3 0.9
Min 0.2 0.9
diff 0.1 0
# awk '{for (i=2; i <=NF; i++) if ($i== "0") $i=$i+0.2; print}' test.txt
Output:
cont x y
Max 0.3 0.9
Min 0.2 0.9
diff 0.1 0.2
Desired Ouput:
cont x y
Max 0.5 1.1
Min 0.1 0.7
diff 0.4 0.4
That is when the diff is 0.1, than add the same column but first row (Max) by 0.2 and subtract same column but second row by 0.1, but when the diff is 0, than add the same column but first row value (Max) by 0.2 and subtract same column but second row by 0.2. AT the end the difference should be 0.4.
Any help will be great.