Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

conditional average

Status
Not open for further replies.

tonivm

Technical User
Mar 2, 2006
64
ES
Hi everybody:

I have files where some values are -9999, and I would like to average some columns each five values but when the value is -9999 will skipped.
I tried this:

awk '{if ($5==-9999) skip; {s+=$5;++c}};{avg=s/5};{if(c==5){print $1, $2, $3, avg ; c=0; s=0}}' $fitxer.tmp2 > $fitxer.cl31;

but do not work correctly.
Somebody couls help me.
Thanks in advance ;)
 

Try:
Code:
awk '$5 != -9999 {s+=$5; ++c} c==5 {print $1,$2,$3,$4,s/5; c=0; s=0}
END {if (c>0) print $1,$2,$3,$4,s/c;}' $fitxer.tmp2 > $fitxer.cl31
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thanks.
But how is it possible when appear a -9999 set for example 5 times the average should be 0.
Thanks again
 

What do you mean by "when appear a -9999 set for example 5 times the average should be 0."?

You requirement is to SKIP the -9999's are you changing this requirement?

[thumbsdown]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top