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

 

 

魂内検索

DOCUMENTS

COMMAND

FORUM

UEC DOCS

VIDEO

 

Alphabetical list

(Video materials in preparation)

cond(USP)

Name

cond : Evaluates an expression to filter records.

Synopsis

Usage   : cond [-i] [+ng[<fd>]] <expr> <file>

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

Edition : 1

Description

The command prints the lines the <expr> holds for each record from <file>.

There are the below expressions as <expr>,

  $<field> == "<string>"    or    $<field> == $<field>

  $<field> != "<string>"    or    $<field> != $<field>

  $<field> > "<string>"    or    $<field> > $<field>

  $<field> >= "<string>"    or    $<field> >= $<field>

  $<field> < "<string>"    or    $<field> < $<field>

  $<field> <= "<string>"    or    $<field> <= $<field>

  $<field> eq <constant>    or    $<field> eq $<field>

  $<field> ne <constant>    or    $<field> ne $<field>

  $<field> lt <constant>    or    $<field> lt $<field>

  $<field> le <constant>    or    $<field> le $<field>

  $<field> gt <constant>    or    $<field> gt $<field>

  $<field> ge <constant>    or    $<field> ge $<field>

  $<field> ~ /<regular expression>/

  $<field> !~ /<regular expression>/

  NF eq <constant>         or    NR eq <contant>

  NF ne <constant>         or    NR ne <contant>

  NF lt <constant>         or    NR lt <contant>

  NF le <constant>         or    NR le <contant>

  NF gt <constant>         or    NR gt <contant>

  NF ge <constant>         or    NR ge <contant>

. As the $-variable, $<index>, $NF and $NF-<constant> can be specified.

There NF means the number of the fields, NR means the number of the records.

These expressions can be combined with && (AND), || (OR), ! (NOT), and

also parenthesized.

When the <file> is not specified, or "-" is given as the <file>,

the command reads from the standard input.

Use the -i option to make the regular expression matching case insensitive.

By setting the +ng<fd> option, the command prints a line the expr does not hold

to a file descriptor <fd>. The command normally prints them to the standard

error output if no <fd> is specified.

Example 1

$ cat file1

111 222 000

110 222 333

111 220 033

110 220 303

$ cond '$1 == "111" && $2 ~ /2$/ || $3 ~ /^[03]0.*$/' file1

111 222 000

110 220 303

$ cond '!($2 <= "221" || $3 !~ /^0.*$/) && $2 ~ /2$/' file1

111 222 000

Example 2

$ cat file2

usp xxx xxx

Usp yyy yyy

USP zzz zzz

$ cond '$1 ~ /usp/' file2

./cond '$1 ~ /usp/' <<<'usp xxx xxx

Usp yyy yyy

USP zzz zzz'

$ cond -i '$1 ~ /usp/' file2

usp xxx xxx

Usp yyy yyy

USP zzz zzz

Example 3

$ cond +ng3 '$2 == "yyy"' file2 >ok-data 3>ng-data

$ cat ok-data

Usp yyy yyy

$ cat ng-data

usp xxx xxx

USP zzz zzz