SUM v2.00 - find sum of numbers in text file |
Revised 2-Jan-99. Copyright (c) 1996-99 by Rune Berg. TextTools Freeware. |
Usage | Description | Options | Example | Limitations | Return Codes | Version History | tt_r6
Usage | Top | Next |
sum [log logfile] [options] [infile] [to outfile]
Description | Top | Previous | Next |
sum sums up numbers in infile until end-of-file or non-numeric data is found, and prints a one line result to outfile, e.g.:
sum is 540
If all input numbers are integers, sum will print an integer result; if at least one input number is a floating point number, sum will print a floating point result.
If sum finds no numbers in infile, it will print:
sum is unknown
If you don't specify infile, sum reads from standard input.
If you don't specify outfile, sum writes to standard output.
If you don't specify logfile, sum writes error messages to standard
error.
Options | Top | Previous | Next |
sum recognizes the following command line options:
Option | Function |
---|---|
-u | Print sum of numbers in infile (default). |
-a | Print average of numbers in infile. |
-s | Print smallest number in infile. |
-b | Print biggest number in infile. |
-c | Print count of numbers in infile. |
-fppN | Use floating-point precision N (0..15, default 6) decimal digits for output. See separate discussion on floating point numbers for more details. |
-fpfF | Use floating point format F for output and internal representation.
F must be one of:
|
-v | Print version banner and usage info to standard error (or logfile, if given), then exit. |
The functions -a -s -b -c -u can be used one at a time (to print just that kind of result), or combined (to print more than one result).
Example | Top | Previous | Next |
Given a file mydata.txt containing:
3 5 1 33the command:
sum -usb mydata.txtwill print:
sum is 42 smallest is 1 biggest is 33
Limitations | Top | Previous | Next |
sum handles integer in the range -2147483647 .. 2147483647.
See separate discussion on floating point numbers for more details on that format.
sum does not detect underflows and overflows.
Return Codes | Top | Previous | Next |
sum returns with one of the following codes ("error levels"):
Code | Meaning |
---|---|
0 | Success |
2 | Unknown result (sum didn't find any numbers to add up). |
102 | Incorrect command line arguments |
104 | Error opening file |
105 | I/O error |
107 | File name clash |
Version History | Top | Previous |
These are the released versions:
Version | Date | Changes |
---|---|---|
1.02 | 25-Feb-96 | n/a |
1.10 | 26-Sep-96 | * Very minor changes. |
1.10 | 11-May-97 | * Now available as Win32 version. |
1.20 | 13-Jul-97 | * Now gives proper return codes. |
2.00 | 2-Jan-99 | * Now supports floating point numbers. * Now allows options to be combined, producing multiple results. * Win32 version now prints coloured response texts. |
End of document |