Question: Help with awk loop

0

Francisco Muñoz •

**10**wrote:Hi everyone! I'm new to awk and i'm having troubles with a script i thought would be easier. I have a variable number of columns with numbers (e.g. 4.45), and some of the "cells" have missing values (--). I have to calculate the mean of each row, adding a new column with it. I tried something like:

```
awk 'BEGIN {FS=";";OFS=";";SUM=0;AVG=0;MSS=0};
NR==1 {print $0,"Average","Missing"};
NR>1 {for (i=4;i<=NF;i++) {if ($i!="--") SUM+=$i};print $0,$SUM; SUM=0}' $FILE
```

In that example i'm not calculating the mean but just the sum as a test, but the results are senseless. I also have to add a "Missing" column where i count the missing values of each row. What am i doing wrong? Thanks in advance!

Thank you all! The error was in the use of $ as kloetzl stated

10