Hi!
I'm having some problems getting AWK to use more than one variable from the shell. In a long bit of code I have the snippet:
suf=00"$i"
molwsuf="$molname"_"$suf"_hbond
h=`cat $molwsuf`
gawk '/'"$molname"_"$suf"'/ {print '"$i"', $2, $4, $6, '"$h"'}' $logfile >> $filename
Where i is an integer that increases by one for every while [ $i -le 9 ] loop. h is either 'no' or 'bond', as defined by a previous condition which then outputs no or bond to the file $molwsuf.
Everything works fine, except for the '"$h"' part. The output I get is:
0 7.51 -2.71 1.93
1 6.79 -1.95 2.26
2 6.70 -1.74 2.17
3 6.63 -2.44 2.31
4 6.56 -2.82 2.63
5 6.44 -3.10 2.68
6 6.23 -2.84 2.60
7 6.09 -2.90 2.66
8 5.95 -3.76 2.27
9 5.68 -4.15 2.78
Which is missing the $h variable (another column at the end). When I echo the gawk line, I get:
gawk '/'c5_nod_r_ou_oz_ar_009'/ {print '9', , , , 'no'}' R500log >> c5_nod_r_ou_oz_ar_tab.log
So the variable is being passed correctly, it's just not being printed (?).
Is there a limit to variables being passed to a single awk strand?
I have tried this using 'X' and 'o' instead of 'no' and 'bond', moving the '"$h"' to various places in the string, and using '"$hb"' instead.
What's going on? Why can't I use more than the one variable? Any ideas on how to get this to correctly print the string?
Thanks so much!
I'm having some problems getting AWK to use more than one variable from the shell. In a long bit of code I have the snippet:
suf=00"$i"
molwsuf="$molname"_"$suf"_hbond
h=`cat $molwsuf`
gawk '/'"$molname"_"$suf"'/ {print '"$i"', $2, $4, $6, '"$h"'}' $logfile >> $filename
Where i is an integer that increases by one for every while [ $i -le 9 ] loop. h is either 'no' or 'bond', as defined by a previous condition which then outputs no or bond to the file $molwsuf.
Everything works fine, except for the '"$h"' part. The output I get is:
0 7.51 -2.71 1.93
1 6.79 -1.95 2.26
2 6.70 -1.74 2.17
3 6.63 -2.44 2.31
4 6.56 -2.82 2.63
5 6.44 -3.10 2.68
6 6.23 -2.84 2.60
7 6.09 -2.90 2.66
8 5.95 -3.76 2.27
9 5.68 -4.15 2.78
Which is missing the $h variable (another column at the end). When I echo the gawk line, I get:
gawk '/'c5_nod_r_ou_oz_ar_009'/ {print '9', , , , 'no'}' R500log >> c5_nod_r_ou_oz_ar_tab.log
So the variable is being passed correctly, it's just not being printed (?).
Is there a limit to variables being passed to a single awk strand?
I have tried this using 'X' and 'o' instead of 'no' and 'bond', moving the '"$h"' to various places in the string, and using '"$hb"' instead.
What's going on? Why can't I use more than the one variable? Any ideas on how to get this to correctly print the string?
Thanks so much!