jeudi 1 août 2019

Awk output not printing after mathmatical operations

I am not getting any of the output to print from my awk command. I believe this is a syntax error, even though the script executes smoothly without calling an error.

My input file looks like

 atom   Comp
 C1 45.7006
 C12    55.5074
 H40    30.0407
 N41    148.389
 F45    365.162

I have some previously defined variables, which I know are being defined correctly as I print them to a separate file to make sure.

 Hslope=-1.1120
 Hint=32.4057
 Cslope=-1.0822
 Cint=196.4234

Currently my code looks like this:

 awk -v Hslope=$Hslope -v Hint=$Hint -v Cslope=$Cslope -v Cint=$Cint 'BEGIN {for(i=1; i<=NF; i++) 
 {
     if($1 ~ /C/) 
     {
     shift = (($2-Cint)/Cslope); print shift
     } 
     else if($1 ~ /H/) 
     {
     shift = (($2-Hint)/Hslope); print shift
     } 
     else 
    {
    print "NA"
    }
 } }' avRNMR >> vgRNMR

Where avRNMR is the input file and vgRNMR is the destination file for the output and has already been created.

I have also tried the same code as above expect the mathematical expression is after print instead of being set to the variable "shift" and have gotten the same results.

What is printed in vgRNMR (which is the destination file name) is

 shift

which was printed by a separate command that also created the file.

What should be printed is

 shift
 139.27
 130.21
 2.13
 NA
 NA

I don't get any errors when executing the script, so I believe that my overall syntax may be correct, but I might be missing something else.

Aucun commentaire:

Enregistrer un commentaire