I have two files. Each has one column with some missing data as 9999, 9000. e.g.
ifile1.txt ifile2.txt
30 20
9999 10
10 40
40 30
10 31
29 9000
9000 9999
9999 9999
31 1250
550 29
I would like to calculate the difference between the averages of the above two files without considering the missing values. i.e.
average (ifile1.txt) - average (ifile2.txt)
I tried like this, but not getting the result.
ave1=$(awk '!/\9999/ && !/\9000/{sum += $1; count++} END {print count ? (sum/count) : count;sum=count=0}' ifile1.txt)
ave2=$(awk '!/\9999/ && !/\9000/{sum += $1; count++} END {print count ? (sum/count) : count;sum=count=0}' ifile2.txt)
result=$(ave1-ave2)
echo $result
Your
awk
will compute the averages but bash won't do floating point arithmetic. You can always usebc
though.-101.429
Also for expressions you have to use
$(( ... ))
Update:
or