total

command module
v0.0.0-...-ded6a28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Total totals columns of its input.

Usage:

total [-F regexp | -csv] [file...]

Total sums the values in the named files (or else standard input). Each file is read as a sequence of records, one per line. Each line is read as a list of space-separated fields in the manner of Go's strings.Fields. Total prints the sum of all the corresponding fields in the records: the total of all the first fields, the total of all the second fields, and so on.

If a given field in any record is non-numeric, meaning it cannot be parsed by Go's strconv.ParseFloat, then the sum for that field is printed as "~". As a special case, if all records contain the same non-numeric string for a given field, then the sum for that field is that string.

The -F flag specifies a Go regular expression to use as an input field separator instead of using strings.Fields. It does not affect the output, which is printed with single spaces between all fields.

The -csv flag specifies that the input lines should be treated as CSV data and that the output should also be printed as CSV data.

Example

Totaling the output of “ls -l” shows that the sources for this program currently total 3,892 bytes:

% ls -l
total 16
-rw-r--r--  1 rsc  primarygroup    35 Oct 29 08:20 go.mod
-rw-r--r--  1 rsc  primarygroup  3857 Oct 29 08:48 total.go
% ls -l | total
~ 18 rsc primarygroup 3892 Oct 58 ~ ~
%

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL