Home of summa

You can mail me at e8johan -at- digitalfanatics.org.
Visit me here!


Instructions

This is the amazing summation command! Download the source here!

Usage: summa [s|p|P|a|A]
  s (default) calculates the sum
  p calculates the product
  P calculates the product (ignores zeroes)
  a calculates the average (integer, no rounding)
  A calculates the average (ignores zeroes)

There are a number of uses for this great command, but first a number of commands to demonstate the different working modes:

Default mode (calculate the sum)

  > echo 1 2 3 4 | summa
  10

Or, forced calculation of the sum

  > echo 1 2 3 4 5 | summa s
  15

Calculation of the product

  > echo 1 2 3 4 | summa p
  24

Calculation of the product, ignoring zeroes (notice that non-numbers are treated as zero)

  > echo 1 foo 2 bar 3 0 5 | summa P
  30

Calculate the average value (Since I don't care for precision, this is an integer only command that truncates the result, i.e. no proper rounding. The real result of the following example should have been 2.333...)

  > echo 1 2 2 3 3 4 1 1 4 | summa a
  2

Calculate the average value, ignoring zeroes (I don't care more for precision here, see note above)

  > echo 0 1 0 2 0 3 foo 5 bar 8 | summa A
  3

The most useful application of this command (according to me) is to calculate the total size of a number of files

  > ls -l *.o | awk '{ print $5; }' | summa

If you have a file with samples in the format 'Time 0.0000: ' the following line can do miracles

  > cat samples.txt | sed 's/[^:]*://g' | summa a

This, of course, assumes that you have integer samples.

If you find any other useful applications of this amazing command, please mail me and tell me (a sample command line may get you included in this README). As for the name, 'summa' is swedish for 'sum'. The other features where added just for fun (product and average).