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

 

 

魂内検索

DOCUMENTS

COMMAND

FORUM

UEC DOCS

VIDEO

 

Alphabetical list

(Video materials in preparation)

getlast(USP)

Name

getlast : Outputs the last record from same key records.

Synopsis

Usage   : getlast <n1> <n2> <file>

          getlast key=<key> <file>

Options : +ng[<fd>]

          -<n>

          -e

          -s<c>

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

Edition : 3

Description

If there are multiple records within the file passed as an argument

or standard input where the specified key fields contains the same

value, only the last record is output.  If -<n> is specified, the

last <n> records are output.

There are tow methods to specify key fields: <n1> <n2> (from <n1>

field to <n2> field) and key=<key>.  <key> designates the key fields

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)

Example 1

(Original Data 1:Product Code 2:Product Name 3:Sale Date 4:Qty Sold)

$ cat data

0000007 Celery 20060201 117

0000007 Celery 20060202 136

0000007 Celery 20060203 221

0000017 Radish 20060201 31

0000017 Radish 20060202 127

0000017 Radish 20060203 514

0000021 Mandarin 20060201 90

0000021 Mandarin 20060202 324

0000021 Mandarin 20060203 573

0000025 Melon 20060201 129

0000025 Melon 20060202 493

0000025 Melon 20060203 391

0000030 Potato 20060201 575

0000030 Potato 20060202 541

0000030 Potato 20060203 184

$ getlast 1 2 data >data2

$ cat data2                 <- Last row with same product is output.

0000007 Celery 20060203 221

0000017 Radish 20060203 514

0000021 Mandarin 20060203 573

0000025 Melon 20060203 391

0000030 Potato 20060203 184

Example 2

The "+ng" option outputs to standard error all rows that match the

key field except for the last row.

$ getlast +ng 1 2 data >/dev/null 2>data2

$ cat data2

0000007 Celery 20060201 117

0000007 Celery 20060202 136

0000017 Radish 20060201 31

0000017 Radish 20060202 127

0000021 Mandarin 20060201 90

0000021 Mandarin 20060202 324

0000025 Melon 20060201 129

0000025 Melon 20060202 493

0000030 Potato 20060201 575

0000030 Potato 20060202 541

Example 3

If <fd> is specified with the +ng option, instead of outputting to

standard error, the command outputs to <fd>.

$ getlast +ng3 1 2 data >/dev/null 3>data2

$ cat data2

0000007 Celery 20060201 117

0000007 Celery 20060202 136

0000017 Radish 20060201 31

0000017 Radish 20060202 127

0000021 Mandarin 20060201 90

0000021 Mandarin 20060202 324

0000025 Melon 20060201 129

0000025 Melon 20060202 493

0000030 Potato 20060201 575

0000030 Potato 20060202 541