D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] AWK multipass



Tom Glare wrote:

How about this ?

#!/usr/bin/awk -f
{
  total += input_number[NR] = $0
}
END {
  for (count = 1; count <= NR; count ++) {
     printf("%0.3f\n",input_number[count] / total
  }
}

On Sun, 1 Feb 2004, Andrew Rogers wrote:

Perfect. Thanks for that.

Now I have different problem, awk doesn't have an erfc() function. I need to process a lot of data and produce graphs, sometimes this involves mathematical functions like erfc(). Maybe I'm trying to use awk beyond its intended purpose. I have used C and C++ in the past but I want to use a script instead. Perl seems to be a solution at the moment, but I still haven't found an erfc() function. I need to learn about Perl modules don't I?

Thanks
Andrew




Today I thought I would learn awk programming so that I could scale a
list of numbers. It seems that awk only does one pass of a file. I need
two passes, the first which simply adds all the numbers, the second
which divides each number by the sum.

Any suggestions?

The file that I need to convert has one number per line, eg.

2.3e-7
4.2e-8
4.7e-8

Should convert to:

0.721
0.132
0.147

Thanks
Andrew


-- The Mailing List for the Devon & Cornwall LUG Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the message body to unsubscribe.





--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.







--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.


Lynx friendly