(Video materials in preparation)
tagsm4 : Inserts subtotal lines.
Usage : tagsm4 <k1> <k2> <d1> <d2> [<s1> <s2>] <file>
tagsm4 key=<key> [dummy=<dummy>] [val=<val>] <file>
Options : -d<string>
-e
-s<c>
Version : Tue Jan 9 09:02:34 JST 2024
Edition : 1
Inserts a "total line" for records in <file> that have the same key.
Tags from <k1> to <k2> and are key fields while tags from <d1> to
<d2> are dummy fields (they are not keys nor are they summed).
Tags from <s1> to <s2> are the summed fields. These fields are
summed for rows with the same key field and a "total line" is
inserted after the last line with the same key. If you do not
specify <s1> and <s2> then all fields starting with the field
following field <d2> are summed.
<key> designates the field position as fllows:
single field TAGa TAGa field
contiguous fields TAGa/TAGb from TAGa field to TAGb field
combination TAGa@TAGb TAGa field and TAGb field
There is no limit on the length of the key field or on the number
of key fields. The key field can also contain multi-byte characters
such as Japanese.
If you specify ":r" as comparison method after the field position,
the fields are compared in reverse order. If you specify ":n" as
comparison method after the field position, that field's values
will be compared as numbers. If you specify ":nr" as comparison
method after the field, the values will be compared in reverse order
as numbers. If you specify comparison method before or after the "/",
you must use the same comparison method for both fields.
TAGa:n/TAGb:n OK
TAGa:n/TAGb:nr Error
TAGa:n/TAGb:r Error
When you specify ":e" as comparison method or specify -e ootion and
no method, characters in the field are replaced as follows and
compared as string:
_ ==> 0x20 (space)
\0 ==> 0x00 (null)
\t ==> 0x09 (tab stop)
\n ==> 0x0a (new line)
\r ==> 0x0d (carrige return)
\_ ==> 0x5f (underscore)
\\ ==> 0x5c (back slash)
The tag name specfying the field can be eclosed by braces {}. In
this case, tag names can include special charcter like "/" or "@".
Moreover, tag names can include pairs of braces. When comparison
method is attached to brace enclosed tag name, ":" should be ommited.
{TAGa}n/{TAGb}n
<val> and <dummy> is same as <key> except no comparison method is
allowed.
"@" characters are inserted in the dummy fields of the total row.
If you use tagsm4 repeatedly to insert subtotals and sub-subtotals
then any record where there is at least one field equal to dummy
value "@" will be excluded.
The "-d<string>" option changes the dummy string as <string>. In
this case, the dummy string is inserted once for each dummy field
regardless the dummy field width. Records which have a dummy field
equivalent to <string> is treated as total row.
Survey Data from Various Cities
$ fcols data
K1 N1 K2 N2 V1 V2 V3 V4 V5
01 Massachusetts 01 Boston 91 59 20 76 54
01 Massachusetts 02 Worcester 46 39 8 5 21
01 Massachusetts 03 Springfield 82 0 23 84 10
02 New_York 04 Manhattan 30 50 71 36 30
02 New_York 05 Brooklyn 78 13 44 28 51
02 New_York 06 Queens 58 71 20 10 6
02 New_York 07 Albany 82 79 16 21 80
02 New_York 08 Buffalo 50 2 33 15 62
03 New_Jersey 09 Newark 52 91 44 9 0
03 New_Jersey 10 Trenton 60 89 33 18 6
03 New_Jersey 11 Moorestown 95 60 35 93 76
04 Pennsylvania 12 Philadelphia 92 56 83 96 75
04 Pennsylvania 13 Pittsburgh 30 12 32 44 19
04 Pennsylvania 14 Lancaster 48 66 23 71 24
Output subtotals by state:
$ tagsm4 K1 N1 K2 N2 V1 V5 data | fcols
K1 N1 K2 N2 V1 V2 V3 V4 V5
01 Massachusetts 01 Boston 91 59 20 76 54
01 Massachusetts 02 Worcester 46 39 8 5 21
01 Massachusetts 03 Springfield 82 0 23 84 10
01 Massachusetts @@ @@ 219 98 51 165 85
02 New_York 04 Manhattan 30 50 71 36 30
02 New_York 05 Brooklyn 78 13 44 28 51
02 New_York 06 Queens 58 71 20 10 6
02 New_York 07 Albany 82 79 16 21 80
02 New_York 08 Buffalo 50 2 33 15 62
02 New_York @@ @@ 298 215 184 110 229
03 New_Jersey 09 Newark 52 91 44 9 0
03 New_Jersey 10 Trenton 60 89 33 18 6
03 New_Jersey 11 Moorestown 95 60 35 93 76
03 New_Jersey @@ @@ 207 240 112 120 82
04 Pennsylvania 12 Philadelphia 92 56 83 96 75
04 Pennsylvania 13 Pittsburgh 30 12 32 44 19
04 Pennsylvania 14 Lancaster 48 66 23 71 24
04 Pennsylvania @@ @@ 170 134 138 211 118
Output subtotals and sub-subtotals.
$ fcols data2
K1 N1 K2 N2 K3 N3 V1 V2 V3 V4 V5
01 Northeast 01 Massachusetts 01 Boston 91 59 20 76 54
01 Northeast 01 Massachusetts 03 Springfield 82 0 23 84 10
01 Northeast 02 New_York 04 Manhattan 30 50 71 36 30
01 Northeast 02 New_York 05 Brooklyn 78 13 44 28 51
01 Northeast 02 New_York 07 Albany 82 79 16 21 80
02 Mid-Atlantic 01 New_Jersey 01 Trenton 91 59 20 76 54
02 Mid-Atlantic 01 New_Jersey 02 Newark 46 39 8 5 21
02 Mid-Atlantic 01 New_Jersey 03 Moorestown 82 0 23 84 10
02 Mid-Atlantic 02 Virginia 04 Arlington 30 50 71 36 30
02 Mid-Atlantic 02 Virginia 05 Reston 78 13 44 28 51
02 Mid-Atlantic 02 Virginia 06 Langley 58 71 20 10 6
02 Mid-Atlantic 02 Virginia 07 Richmond 82 79 16 21 80
02 Mid-Atlantic 02 Virginia 08 Norfolk 50 2 33 15 62
02 Mid-Atlantic 03 Delaware 09 Dover 52 91 44 9 0
02 Mid-Atlantic 03 Delaware 10 Rehobeth 60 89 33 18 6
$ tagsm4 K1 N2 K3 N3 V1 V5 data2 | tagsm4 K1 N1 K2 N3 V1 V5 | fcols
K1 N1 K2 N2 K3 N3 V1 V2 V3 V4 V5
01 Northeast 01 Massachusetts 01 Boston 91 59 20 76 54
01 Northeast 01 Massachusetts 03 Springfield 82 0 23 84 10
01 Northeast 01 Massachusetts @@ @@ 173 59 43 160 64
01 Northeast 02 New_York 04 Manhattan 30 50 71 36 30
01 Northeast 02 New_York 05 Brooklyn 78 13 44 28 51
01 Northeast 02 New_York 07 Albany 82 79 16 21 80
01 Northeast 02 New_York @@ @@ 190 142 131 85 161
01 Northeast @@ @@ @@ @@ 363 201 174 245 225
02 Mid-Atlantic 01 New_Jersey 01 Trenton 91 59 20 76 54
02 Mid-Atlantic 01 New_Jersey 02 Newark 46 39 8 5 21
02 Mid-Atlantic 01 New_Jersey 03 Moorestown 82 0 23 84 10
02 Mid-Atlantic 01 New_Jersey @@ @@ 219 98 51 165 85
02 Mid-Atlantic 02 Virginia 04 Arlington 30 50 71 36 30
02 Mid-Atlantic 02 Virginia 05 Reston 78 13 44 28 51
02 Mid-Atlantic 02 Virginia 06 Langley 58 71 20 10 6
02 Mid-Atlantic 02 Virginia 07 Richmond 82 79 16 21 80
02 Mid-Atlantic 02 Virginia 08 Norfolk 50 2 33 15 62
02 Mid-Atlantic 02 Virginia @@ @@ 298 215 184 110 229
02 Mid-Atlantic 03 Delaware 09 Dover 52 91 44 9 0
02 Mid-Atlantic 03 Delaware 10 Rehobeth 60 89 33 18 6
02 Mid-Atlantic 03 Delaware @@ @@ 112 180 77 27 6
02 Mid-Atlantic @@ @@ @@ @@ 629 493 312 302 320
Special Case (No Dummy Field)
$ fcols data3
N1 V1 V2 V3 V4 V5
Massachusetts 91 59 20 76 54
Massachusetts 46 39 8 5 21
Massachusetts 82 0 23 84 10
New_York 30 50 71 36 30
New_York 78 13 44 28 51
New_York 58 71 20 10 6
New_York 82 79 16 21 80
New_York 50 2 33 15 62
New_Jersey 52 91 44 9 0
New_Jersey 60 89 33 18 6
New_Jersey 95 60 35 93 76
Pennsylvania 92 56 83 96 75
Pennsylvania 30 12 32 44 19
Pennsylvania 48 66 23 71 24
$ tagsm4 N1 N1 - - V1 V5 data3 | fcols
N1 V1 V2 V3 V4 V5
Massachusetts 91 59 20 76 54
Massachusetts 46 39 8 5 21
Massachusetts 82 0 23 84 10
@@ 219 98 51 165 85
New_York 30 50 71 36 30
New_York 78 13 44 28 51
New_York 58 71 20 10 6
New_York 82 79 16 21 80
New_York 50 2 33 15 62
@@ 298 215 184 110 229
New_Jersey 52 91 44 9 0
New_Jersey 60 89 33 18 6
New_Jersey 95 60 35 93 76
@@ 207 240 112 120 82
Pennsylvania 92 56 83 96 75
Pennsylvania 30 12 32 44 19
Pennsylvania 48 66 23 71 24
@@ 170 134 138 211 118
-d<string> option
$ fcols data4
K1 N1 K2 N2 V1 V2 V3 V4 V5
01 Massachusetts 01 Boston 91 59 20 76 54
01 Massachusetts 02 Worcester 46 39 8 5 21
01 Massachusetts 03 Springfield 82 0 23 84 10
02 New_York 04 Manhattan 30 50 71 36 30
02 New_York 05 Brooklyn 78 13 44 28 51
02 New_York 06 Queens 58 71 20 10 6
02 New_York 07 Albany 82 79 16 21 80
02 New_York 08 Buffalo 50 2 33 15 62
03 New_Jersey 09 Newark 52 91 44 9 0
03 New_Jersey 10 Trenton 60 89 33 18 6
03 New_Jersey 11 Moorestown 95 60 35 93 76
04 Pennsylvania 12 Philadelphia 92 56 83 96 75
04 Pennsylvania 13 Pittsburgh 30 12 32 44 19
04 Pennsylvania 14 Lancaster 48 66 23 71 24
Output subtotals by state:
$ tagsm4 -d+++ K1 N1 K2 N2 V1 V5 data4 | fcols
K1 N1 K2 N2 V1 V2 V3 V4 V5
01 Massachusetts 01 Boston 91 59 20 76 54
01 Massachusetts 02 Worcester 46 39 8 5 21
01 Massachusetts 03 Springfield 82 0 23 84 10
01 Massachusetts +++ +++ 219 98 51 165 85
02 New_York 04 Manhattan 30 50 71 36 30
02 New_York 05 Brooklyn 78 13 44 28 51
02 New_York 06 Queens 58 71 20 10 6
02 New_York 07 Albany 82 79 16 21 80
02 New_York 08 Buffalo 50 2 33 15 62
02 New_York +++ +++ 298 215 184 110 229
03 New_Jersey 09 Newark 52 91 44 9 0
03 New_Jersey 10 Trenton 60 89 33 18 6
03 New_Jersey 11 Moorestown 95 60 35 93 76
03 New_Jersey +++ +++ 207 240 112 120 82
04 Pennsylvania 12 Philadelphia 92 56 83 96 75
04 Pennsylvania 13 Pittsburgh 30 12 32 44 19
04 Pennsylvania 14 Lancaster 48 66 23 71 24
04 Pennsylvania +++ +++ 170 134 138 211 118