compute - compute data field values
compute [options] [statements]
eval'd.
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
See the rdb_expr document for information on how to specify expressions.