You are not logged in.

#1 2011-04-21 16:33:12

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

[solved] calculate average from data file

Hi everyone,

i've got a very simple data file with >300 4-5 digit numbers, one per line. It looks like this:

5576
5576
5624
5624
5464
5464
6380
6380
17364

Now I'm looking for an easy way to calculate the average of the sum of those numbers.

I'd appreciate some help.

Thanks.



//

awk '{ total += $1; count++ } END { print total/count }' file
OR
awk 'BEGIN{s=0;}{s+=$1;}END{print s/NR;}' file

Last edited by demian (2011-04-21 16:50:10)


no place like /home
github

Offline

#2 2011-04-21 16:36:18

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: [solved] calculate average from data file

You don't even mention what programming language you intend to use.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#3 2011-04-21 16:40:27

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: [solved] calculate average from data file

That's because any language typically present on an arch box would have done. Guess I should have mentioned that.
Anyway, I found a way to do it with awk.
Why do I always find the right search phrases AFTER posting here? Sorry hmm
Solved.

Last edited by demian (2011-04-21 16:45:05)


no place like /home
github

Offline

Board footer

Powered by FluxBB