[ Date Index ][
Thread Index ]
[ <= Previous by date /
thread ]
[ Next by date /
thread => ]
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:
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.