LinuxSA Mailing list archives
Index:
[thread]
[date]
[subject]
[author]
From: justin@tardis.mx.com.au
To : Gaelyne Gasson <gaelyne@videocam.net.au>
Date: Sat, 1 May 1999 20:14:01 +0930 (CST)
Re: Unidentified subject!
On Sat, 1 May 1999, Gaelyne Gasson wrote:
> G'day,
>
> I have a list of numbers in a file (one number per line). What's an
> easy way via a script file of adding them up to find the sum of the
> file?
I love these things!!!
The gawk way:
cat numbers | gawk '{ total += $1} END {print total }'
The perl way:
cat numbers | perl -e 'while (<>) { $total += $_} ; print "$total\n";'
The C way:
Nah.....
I'm sure my perl one can be optimized heaps - I want to learn more about
writing those one line perl scripts.
- Justin
--
Check out the LinuxSA web pages at http://www.linuxsa.org.au/
To unsubscribe from the LinuxSA list:
mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject
Index:
[thread]
[date]
[subject]
[author]
Return to the LinuxSA Mailing List Information Page