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

 

 

魂内検索

DOCUMENTS

COMMAND

FORUM

UEC DOCS

VIDEO

 

Alphabetical list

(Video materials in preparation)

loopj(USP)

Name

loopj : Join all records from multiple files by key.

Synopsis

Usage   : loopj num=<num> <file1> <file2> ...

Options : -d<string>

          -e

          -s<c>

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

Edition : 1

Description

The specified text files are joined together using as the key field

the first to the <n>th field.

If there is no matching field in each file, then its output will be

padded with "0".

<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)

The files to be joined must be greater than zero bytes in size, and the

key field must contain only unique values sorted in ascending order.

If <file> is a zero byte file, an error is generated.

Example 1 Basic Usage

(file1)

0000003 Wilson_____ A

0000005 Hawking____ B

0000007 Newton_____ C

0000010 Tesla______ D

(file2)

0000000 50

0000003 26

0000004 40

0000009 68

(file3)

0000000 F

0000003 F

0000004 M

0000005 F

Join three files.

$ loopj num=1 file1 file2 file3 > data

(data)

0000000 0 0 50 F

0000003 Wilson_____ A 26 F

0000004 0 0 40 M

0000005 Hawking____ B 0 F

0000007 Newton_____ C 0 0

0000009 0 0 68 0

0000010 Tesla______ D 0 0

If a filename is specified as "-" then the command will

read from standard input.

$ cat file2 | loopj num=1 file1 - file3

Example 2 -d option

You can specify the string used for padding

$ loopj -d@@@ num=1 file1 file2 file3 > data

$ cat data

0000000 @@@ @@@ 50 F

0000003 Wilson_____ A 26 F

0000004 @@@ @@@ 40 M

0000005 Hawking____ B @@@ F

0000007 Newton_____ C @@@ @@@

0000009 @@@ @@@ 68 @@@

0000010 Tesla______ D @@@ @@@

Example 3 If you specify files that only contain keys,

only the value is padded.

$ cat file1

0001 1

0002 2

$ cat file2

0001

0002

0003

0004

$ loopj num=1 file1 file2 OR

$ loopj num=1 file2 file1

0001 1

0002 2

0003 0

0004 0

$ loopj num=1 file2 file2

0001

0002

0003

0004

Important

If a file to be joined is zero bytes, an error occurs.

$ : > data1

$ cat data2

a 1

b 2

c 3

$ loopj num=1 data1 data2

Error[loopj] : Cannot join a zero-byte file [1].

In the above example, to ensure that data1 has three fields:

$ [ ! -s data1 ] && echo x 0 0 > data1

$ loopj num=1 data1 data2 | awk '$1!~/x/'

a 0 0 1

b 0 0 2

c 0 0 3