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

 

 

魂内検索

DOCUMENTS

COMMAND

FORUM

UEC DOCS

VIDEO

 

Alphabetical list

(Video materials in preparation)

self(USP)

Name

self : Outputs the data from the specified fields

       self = select fields

Synopsis

Usage   : self <f1> <f2> ... <file>

          self -d <f1> <f2> ... <string>

Option  : -n<string>

          -f

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

Edition : 3

Description

Outputs the data from the specified field in <file>.

If <file> is not specified or is "-" then the command reads from

standard input.

Options

-d : Direct Mode

     Executes the self command on "<string>"

Example 1

Outputs text data from the 4th field and the 2nd field.

$ cat data

0000000 Smith______ 50 F 91 59 20 76 54

0000001 Jones______ 50 F 46 39 8  5 21

0000003 Wilson_____ 26 F 30 50 71 36 30

0000004 Drake______ 40 M 58 71 20 10 6

0000005 Hawking____ 50 F 82 79 16 21 80

$ self 4 2 data

F Smith______

F Jones______

F Wilson_____

M Drake______

F Hawking____

Example 2

"self" can output a substring from the field.

(Same function as using the "substr" function of "awk".)

Outputs a substring of the first field beginning with the fourth character.

$ self 1.4 2 data

0000 Smith______

0001 Jones______

0003 Wilson_____

0004 Drake______

0005 Hawking____

Outputs a substring from the first to the fourth character of the 2nd field.

$ self 2.1.4 3 data

Smith 50

Jones 50

Wilson 26

Drake 40

Hawking 50

Example 3

Specifying record "0" outputs the whole line.

$ self 0 data

0000000 Smith______ 50 F 91 59 20 76 54

0000001 Jones______ 50 F 46 39 8  5 21

0000003 Wilson_____ 26 F 30 50 71 36 30

0000004 Drake______ 40 M 58 71 20 10 6

0000005 Hawking____ 50 F 82 79 16 21 80

$ self 4 0 data

F 0000000 Smith______ 50 F 91 59 20 76 54

F 0000001 Jones______ 50 F 46 39 8 5 21

F 0000003 Wilson_____ 26 F 30 50 71 36 30

M 0000004 Drake______ 40 M 58 71 20 10 6

F 0000005 Hawking____ 50 F 82 79 16 21 80

Example 4

You can specify contiguous fields.

$ self 2/5 data

Smith______ 50 F 91

Jones______ 50 F 46

Wilson_____ 26 F 30

Drake______ 40 M 58

Hawking____ 50 F 82

Example 5

You can specify the last field by NF (total Number of Fields)

$ self 1 NF-3 NF data

0000000 59 54

0000001 39 21

0000003 50 30

0000004 71 6

0000005 79 80

Example 6

You can treat multiple blank fields as a single blank.

$ cat data2

   a    b  

c   d e

$ self 1/NF data2

a b

c d e

Example 7

Using direct mode, you can process a text string.

$ self -d 1.1.4 "20070401 12345"

2007

Example 8

When specifying a substr with self, the first character is designated 1.

$ echo ABCDEFGHIJ | self 1.3.4

CDEF

Important

If the input file is not terminated with a linefeed, then

a linefeed is inserted at the end of the file to create a

properly-terminated line.

Important

Do not use files whose filename is entirely numeric.

If there exists a file whose filename is "10", then when you

run self 1 10 --> it will select the first field from the file

named "10" instead of selecting 1st fileld and 10th fileld from

standard input.

However, if you specify fields with only one digit (i.e. "2"), then

even if there is a file named "2" it will be ignored and "2" will

be considered the field designator.

Important

If you specify substr to start or end in the middle of a two-byte character

then an error occurs.

$ echo USP研究所 | self 1.2.4 2

Error(792)[self] : Rec.1 error.

If you specify a position greater than the field width or before top

of thefield, an error occurs.

$ echo USP 研究所 | self 1.20 2

Error(788)[self] : Rec.1 error.

$ echo USP 研究所 | self 1.-20 2

Error(770)[self] : Rec.1 error.

If you specify -n<string> option, no error occurs and the field becomes

<string>.

$ echo USP 研究所 | self -n_ 1.20 2

_ 研究所