(Video materials in preparation)
delkey : Deletes the key field from consecutive records.
Usage : delkey [option] num=<n> <file>
Option : -d<chr>
-i<str>
-h
Version : Thu Apr 14 11:06:10 JST 2016
Edition : 1
Using field 1 to field <n> as the key, convert the key field in
consecutive records of <file> that share the same key to spaces,
starting with the second record sharing the same key.
You can specify a different padding character with the -d option.
The -i option specifies a string to replace the key field.
The -h option specifies the partial deletion mode. In this mode,
same key fields from top of the line are replaced. This option
can be used with the the -d option or the -i option.
$ cat data
001 Texas 01 Austin 91 59 20 76 54
001 Texas 01 Austin 46 39 8 5 21
001 Texas 02 Houston 82 0 23 84 10
001 Texas 02 Houston 45 93 28 61 23
002 New_York 01 Bronx 30 50 71 36 30
002 New_York 01 Bronx 78 13 44 28 51
002 New_York 02 Queens 39 22 13 76 08
002 New_York 02 Queens 58 71 20 10 6
003 Connecticut 01 Hartford 52 91 44 9 0
003 Connecticut 01 Hartford 60 89 33 18 6
003 Connecticut 02 New_Haven 92 56 83 96 75
003 Connecticut 02 New_Haven 30 12 32 44 19
$ delkey num=2 data
001 Texas 01 Austin 91 59 20 76 54
01 Austin 46 39 8 5 21
02 Houston 82 0 23 84 10
02 Houston 45 93 28 61 23
002 New_York 01 Bronx 30 50 71 36 30
01 Bronx 78 13 44 28 51
02 Queens 39 22 13 76 08
02 Queens 58 71 20 10 6
003 Connecticut 01 Hartford 52 91 44 9 0
01 Hartford 60 89 33 18 6
02 New_Haven 92 56 83 96 75
02 New_Haven 30 12 32 44 19
Uses "@" as the padding character.
$ delkey -d@ num=2 data
001 Texas 01 Austin 91 59 20 76 54
@@@ @@@@@ 01 Austin 46 39 8 5 21
@@@ @@@@@ 02 Houston 82 0 23 84 10
@@@ @@@@@ 02 Houston 45 93 28 61 23
002 New_York 01 Bronx 30 50 71 36 30
@@@ @@@@@@@@ 01 Bronx 78 13 44 28 51
@@@ @@@@@@@@ 02 Queens 39 22 13 76 08
@@@ @@@@@@@@ 02 Queens 58 71 20 10 6
003 Connecticut 01 Hartford 52 91 44 9 0
@@@ @@@@@@@@@@@ 01 Hartford 60 89 33 18 6
@@@ @@@@@@@@@@@ 02 New_Haven 92 56 83 96 75
@@@ @@@@@@@@@@@ 02 New_Haven 30 12 32 44 19
Replaces the fields with "@".
$ delkey -i@ num=2 data | fcols
001 Texas 01 Austin 91 59 20 76 54
@ @ 01 Austin 46 39 8 5 21
@ @ 02 Houston 82 0 23 84 10
@ @ 02 Houston 45 93 28 61 23
002 New_York 01 Bronx 30 50 71 36 30
@ @ 01 Bronx 78 13 44 28 51
@ @ 02 Queens 39 22 13 76 08
@ @ 02 Queens 58 71 20 10 6
003 Connecticut 01 Hartford 52 91 44 9 0
@ @ 01 Hartford 60 89 33 18 6
@ @ 02 New_Haven 92 56 83 96 75
@ @ 02 New_Haven 30 12 32 44 19
Partial deletion mode.
$ delkey -h num=4 data
001 Texas 01 Austin 91 59 20 76 54
46 39 8 5 21
02 Houston 82 0 23 84 10
45 93 28 61 23
002 New_York 01 Bronx 30 50 71 36 30
78 13 44 28 51
02 Queens 39 22 13 76 08
58 71 20 10 6
003 Connecticut 01 Hartford 52 91 44 9 0
60 89 33 18 6
02 New_Haven 92 56 83 96 75
30 12 32 44 19
If the number of fields is less than <n>, the whole line is used as
a key.
$ cat data2
001 Texas 01 Austin 91 59 20 76 54
001 Texas 01 Austin 46 39 8 5 21
-------------------------------------------
-------------------------------------------
001 Texas 02 Houston 82 0 23 84 10
001 Texas 02 Houston 45 93 28 61 23
$ delkey num=2 data2
001 Texas 01 Austin 91 59 20 76 54
01 Austin 46 39 8 5 21
-------------------------------------------
001 Texas 02 Houston 82 0 23 84 10
02 Houston 45 93 28 61 23