开发者

AWK: how to reuse a result NR-times without removing END?

How can I get all differences, not just one? I want to use the calculated result for each item in the third column. The dilemma is that if I remove END I can print $3 but cannot have ave.开发者_JAVA百科 If I leave END I have ave but not all differences.

awk '{sum+=$3} END {ave=sum/NR} END {print $3-ave}' coriolis_data
-0.00964   // I want to see the rest differences, how?

coriolis_data

.105    0.005   0.9766  0.0001  0.595   0.005
.095    0.005   0.9963  0.0001  0.595   0.005
.115    0.005   0.9687  0.0001  0.595   0.005
.105    0.005   0.9693  0.0001  0.595   0.005
.095    0.005   0.9798  0.0001  0.595   0.005
.105    0.005   0.9798  0.0001  0.595   0.005
.095    0.005   0.9711  0.0001  0.595   0.005
.110    0.005   0.9640  0.0001  0.595   0.005
.105    0.005   0.9704  0.0001  0.595   0.005
.090    0.005   0.9644  0.0001  0.595   0.005


then you create another array to store $3 values. And use only 1 END block

awk '{sum+=$3;s3[NR]=$3} END {ave=sum/NR; for(i=1;i<=NR;i++)print s3[i]-ave}' coriolis_data
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜