SUM v2.01 - find sum of numbers in text file |
Documentation revised 21 Oct 00 - Copyright (c) 1996-2000 by Rune Berg. TextTools Freeware. |
Contents:
Usage | Top || Next |
sum [log logfile] [options] [infile] [to outfile]
See Understanding The Usage Section for details.
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 comparisons/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 33
the command:
sum -usb mydata.txt
will 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 found no numbers to add up). |
102 | Incorrect/missing command line arguments |
104 | Error opening file |
105 | I/O Error |
107 | File name clash |
For more details, see TextTools General Features.
Version History | Top || Previous |
These are the released versions of sum:
Version | Date | Changes |
---|---|---|
1.02 | 25-Feb-96 | n/a |
1.10 | 26-Sep-96 |
|
1.10 | 11-May-97 |
|
1.20 | 13-Jul-97 |
|
2.00 | 2-Jan-99 |
|
2.01 | 21-Oct-00 |
|
End of document |