NAME

compute - compute data field values


SYNOPSIS

compute [options] [statements]


OPTIONS

-help
Print this help information.

-f XXX
The statements are in the file XXX, instead of on the command line. The advantage in this case is that no quoting of characters that might be special to the UNIX shell is necessary.

-d column[,def]
override the column type definition for column in the rdb file, setting it to def, if specified, or the opposite of the current definition, if def is not specified.

-x
Print out the Perl script which will be eval'd.


DESCRIPTION

Computes values for data fields based on arbitrary statements using column names. Any characters that are special to the UNIX shell must be quoted.

This operator reads a rdbtable via STDIN and writes a rdbtable via STDOUT. Options may be abbreviated.

If a file is used to contain the statements any line in the file that starts with a sharp sign (#) is treated as a comment and ignored. Also if there is a sharp sign preceded by a space character anywhere on the line the rest of the line is also treated as a comment.

The command:

        compute  count  +=  100  if  type  lt  D  <  cfile  |  ptbl

gives the output:

        name    count  type    amt
        ------  -----  ----  -----
        Bush      103  A       133
        Hansen    139  A        23
        Newton      8  E         8
        Hobbs     142  B       144
        Hart      102  C        55
        Jones     104  B       244
        Smith       5  D      1111

Example file of commands named 'XXX':

        if( type eq A ){ 
          name = NEW ;
          amt = count * 2 ; 
          type = 'AAA' ;
        } else {
           name = OLD ;
           amt = count + 1000 ;
           type = 'ZZZ' ;
        }

Output from command:

        compute  -fXXX  <  cfile  |  ptbl

would be:

        name    count  type    amt
        ------  -----  ----  -----
        NEW         3  AAA       6
        NEW        39  AAA      78
        OLD         8  ZZZ    1008
        OLD        42  ZZZ    1042
        OLD         2  ZZZ    1002
        OLD         4  ZZZ    1004
        OLD         5  ZZZ    1005

Expressions

See the rdb_expr document for information on how to specify expressions.