3.25 mkeybreak Keybreak Point

Add an indicator to first rows and last rows of each key specified at k= parameter. The first row is indicated as 1 in the top field, and the same indicator is added to last row in the bot column. Records that are not in the first row nor last row will appear as NULL values.

Format

mkeybreak k= [s=] [a=] [i=] [o=] [-nfn] [-nfno] [-x] [-q] [--help] [--version]

Parameter

k=

Specify field names (multiple fields can be specified) of the aggregate key.

s=

After sorted by specified fields (multiple fields can be specified), the first and last rows are marked.

a=

Specify the field name for top and bottom indicators in the output. [default value: top,bot]

Examples

Example 1: Basic Example

Sort the records by ¥verb|k1| field, add an indicator (1) to the first record (top field) and last record (bottom field) where k1 is key field.

$ more dat1.csv
id,k1,k2,val
1,A,a,1
2,A,b,2
3,A,b,3
4,B,a,4
5,B,a,5
$ mkeybreak k=k1 i=dat1.csv o=rsl1.csv
#END# kgkeybreak i=dat1.csv k=k1 o=rsl1.csv
$ more rsl1.csv
id,k1%0,k2,val,top,bot
1,A,a,1,1,
2,A,b,2,,
3,A,b,3,,1
4,B,a,4,1,
5,B,a,5,,1

Example 2: 2 key fields

After fields k1 and k2 are sorted, the beginning of key field k1 (topfield) and end (bottomfield) is marked (1).

$ mkeybreak s=k1,k2 k=k1 i=dat1.csv o=rsl2.csv
#END# kgkeybreak i=dat1.csv k=k1 o=rsl2.csv s=k1,k2
$ more rsl2.csv
id,k1,k2,val,top,bot
1,A,a,1,1,
2,A,b,2,,
3,A,b,3,,1
4,B,a,4,1,
5,B,a,5,,1

Related Command