This is best explained by way of an example. Suppose the file data contains the lines:
x y z v - - - - 1 1 2 3 1 1 3 4 2 3 4 5 2 4 5 6 2 4 6 7where exactly one tab-character separates the columns.
The command subtotal by x y on z v < data yields
x y z v - - - - 1 1 5 7 2 3 4 5 2 4 11 13on the standard output.
Note that the input must be sorted on the by-columns in some fashion, so that all instances of equivalent lines are adjacent.
On-columns and by-columns can be intermixed in the input. Other columns in the input are ignored in the computations and are not output.
Subtotal
calls upon two other programs,
project
and
addcol
to do the work. This is inefficient but the inefficiency is rarely noticable.RogueMonsterelse
echo "will not over write ./doc/subtotal.1"
fi
if `test ! -s ./doc/union.1`
then
echo "writting ./doc/union.1"
cat > ./doc/union.1 << 'RogueMonster'
The union command simply concatenates two files, appending the second to the first, but using only the header of the first file.
With the two files, data1:
first second third ----- ------ ----- 1 3 0 1 2 3and data2:
first second third ----- ------ ----- 2 3 4 3 4 5 4 5 6the command union data1 data2 yields:
first second third ----- ------ ----- 1 3 0 1 2 3 2 3 4 3 4 5 4 5 6on the standard output.
Note that the two input files must have the same columns, in the same order.