Passing variables into awk from bash
awk, bash, ubuntu-12.04
Solution
avg=1+3*$nprop
This will set `$avg` to `1+3*4`, literally, if `$prop` is 4 for instance. You should be evaluating that expression:
avg=$(( 1+3*$nprop ))
And use the version of the `awk` script with parenthesis.
Problem
I am writing a shell script file in which I have to print certain columns of a file. So I try to use awk. The column numbers are calculated in the script. Nprop is a variable in a for loop, that changes from 1 to 8. ``` avg=1+3*$nprop awk -v a=$avg '{print $a " " $a+1 " " $a+2}' $filename5 >> neig5.dat ``` I have tried the following also: ``` awk -v a=$avg '{print $a " " $(a+1) " " $(a+2) }' $filename5 >> neig5.dat ``` This results in printing the first three columns all the time.