uspTukubaiコマンドに関する様々な資料がここにあります。

 

 

魂内検索

DOCUMENTS

COMMAND

FORUM

UEC DOCS

VIDEO

 

Alphabetical list

(Video materials in preparation)

cjoin2(USP)

Name

cjoin2 : Sequential key matching join

Synopsis

Usage   : cjoin2 key=<key> <master> <tran>

Options : +<string>

          -f<n>

          -e

          -s<c>

Version : Tue Jan  9 09:02:34 JST 2024

Edition : 1

Description

Only those records in the text file <tran> where the <key> fields of

<tran> match corresponding fields of <master> are selected, then

joined with the fields in <master> and output.  The join occurs by

adding the fields from <master> immediately after the <key> fields

in <tran>.  For records that do not match, padding data "_" is joined

for the amount of fields in master. It is also possible to specify

different padding data by +<string> option.

<key> designates the field position as fllows:

single field       2        the 2nd field

                   NF   the last field

                   NF-1   the field just before the last field

contiguous fields  2/4      from the 2nd field to the 4th field

                   4/2   from the 4th field to the 2nd field

                   NF-3/NF  from NF-3 field to the NF field

combination        2@NF     the 2nd field and the NF 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.

  2n/5n     OK

  2n/5nr    Error

  2n/5r     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)

In all cases, the master must be sorted for the specified key. (The

transaction file need not be sorted).

If <master> is an empty file (0 bytes) an error is generated. If

-f<n> option is specified, this error is not generated and <n> is

used as number of non-key fields of <master>.

If "-" is specified for <master> then the command reads from

standard input. If "-" is specified for <tran> or if <tran> is

omitted then thecommand reads from standard input.

cjoin2 reads the entire <master> file into memory, so if <master>

is extremely large a memory allocation error can occur.

Example 1 Normal Usage

$ cat master

0000003 Wilson_____ 26 F

0000005 Hawking____ 50 F

0000007 Newton______ 42 F

$ cat tran

0000005 82 79 16 21 80

0000001 46 39 8  5 21

0000004 58 71 20 10 6

0000009 60 89 33 18 6

0000003 30 50 71 36 30

0000007 50 2  33 15 62

$ cjoin2 key=1 master tran > ok

$ cat ok

0000005 Hawking____ 50 F 82 79 16 21 80

0000001 _ _ _ 46 39 8  5 21

0000004 _ _ _ 58 71 20 10 6

0000009 _ _ _ 60 89 33 18 6

0000003 Wilson_____ 26 F 30 50 71 36 30

0000007 Newton______ 42 F 50 2  33 15 62

Example 2 Usage of +<string> option

$ cjoin2 +@ key=1 master tran > ok

$ cat ok

0000005 Hawking____ 50 F 82 79 16 21 80

0000001 @ @ @ 46 39 8  5 21

0000004 @ @ @ 58 71 20 10 6

0000009 @ @ @ 60 89 33 18 6

0000003 Wilson_____ 26 F 30 50 71 36 30

0000007 Newton_____ 42 F 50 2  33 15 62

Example 3 Read file from standard input

$ cat tran | cjoin2 +ng key=1 master

$ cat tran | cjoin2 +ng key=1 master -

$ cat master | cjoin2 +ng key=1 - tran

Example 4 -f<n> option

$ cjoin2 -f3 key=1 /dev/null tran > ok

$ cat ok

0000005 _ _ _ 82 79 16 21 80

0000001 _ _ _ 46 39 8  5 21

0000004 _ _ _ 58 71 20 10 6

0000009 _ _ _ 60 89 33 18 6

0000003 _ _ _ 30 50 71 36 30

0000007 _ _ _ 50 2  33 15 62

Note 1

The +<string> option is the same as the deprecated "-d <string>" option

The "-d <string>" will be removed in the future.