(Video materials in preparation)
hsum : Horizontal sum.
Usage : hsum [-d<str>] [+<n>h] [num=<n>] <file>
Version : Tue Jul 19 16:00:07 JST 2016
Edition : 1
This tool sums up all of the fields in each record of <file> and
adds the sum as a field to the end of each record. It sums all
fields starting with the (<n> + 1)th field to the last field in the
record, and adds the sum as a field at the end of the record. If
"num=<n>" is omitted, "num=0" is assumed.
If "-d<str>" option is specified, fields which value is "<str>" are
treated as "0".
(Original Data:data1) ID Name Age Gender A B C D E
$ fcols data1
0000000 Smith______ 50 F 91 59 20 76 54
0000001 Jones______ 50 F 46 39 8 5 21
0000003 Wilson_____ 26 F 30 50 71 36 30
0000004 Drake______ 40 M 58 71 20 10 6
0000005 Hawking____ 50 F 82 79 16 21 80
0000007 Newton_____ 42 F 50 2 33 15 62
Grades per class (all fields starting from the 5th field)
are summed and the sum is added to the end of the record.
$ hsum num=4 data1 | fcols
0000000 Smith______ 50 F 91 59 20 76 54 300
0000001 Jones______ 50 F 46 39 8 5 21 119
0000003 Wilson_____ 26 F 30 50 71 36 30 217
0000004 Drake______ 40 M 58 71 20 10 6 165
0000005 Hawking____ 50 F 82 79 16 21 80 278
0000007 Newton_____ 42 F 50 2 33 15 62 162
^^^Sum of fields 5 - 9
"+<n>h" option:
The top <n> records are treated as the header lines. The header lines
are added "@" instead of the sum. The first line is treated as header
line when <n> is omitted.
(Original Data:data2)
$ fcols data2
ID Name Age Gender A B C D E
0000000 Smith______ 50 F 91 59 20 76 54
0000001 Jones______ 50 F 46 39 8 5 21
0000003 Wilson_____ 26 F 30 50 71 36 30
0000004 Drake______ 40 M 58 71 20 10 6
0000005 Hawking____ 50 F 82 79 16 21 80
0000007 Newton_____ 42 F 50 2 33 15 62
Grades per class (all fields starting from the 5th field)
are summed and the sum is added to the end of the record,
skipping the first row.
$ hsum +h num=4 data2 | fcols
ID Name Age Gender A B C D E @ <- "@" is added to first row
0000000 Smith______ 50 F 91 59 20 76 54 300
0000001 Jones______ 50 F 46 39 8 5 21 119
0000003 Wilson_____ 26 F 30 50 71 36 30 217
0000004 Drake______ 40 M 58 71 20 10 6 165
0000005 Hawking____ 50 F 82 79 16 21 80 278
0000007 Newton_____ 42 F 50 2 33 15 62 162
^^^Sum of fields 5 - 9