[Previous] [Next] [Up] [Top] [Edit]


compute - compute column values for the rows of a starbase data table


        compute 'statements' < tablefile


compute executes a list of awk statements on each row of a starbase data table. Each statement is separated from the next by a semi-colon or newline. compute is very useful for computing values for new columns in a table.

The statements or expression is preprocessed by the program before passed to awk for evaluation. Column and header value names are substituted for thier values in the table. Column names may be subscripted with an array index and the column data will be split on the ARRDEL environment variable. Header values may be also subscripted, but assignments made to header values will not appear in the output table.

The user statements and expressions of are interpreted by the awk programming langauge.



When computing numeric columns with more than 6 significant figures it may be necessary to set the formatting values that compute uses to convert numeric value back into text for printing. The CONVFMT value specifies a printf spec for converting a number to text interanlly to compute and OFMT specifies a printf spec for converting a number text for output. When CONVFMT is set OFMT is also set to the same value.

This is usually done on the command line with the -v option:

    john@panic : compute -v CONVFMT="%.9g" < tab 'XY = X*Y'


Assign the a new value to the "dist" column in a table. Since compute does not create new columns to hold computed values, it is often used with "column -a newcolumn" as in this example.

    john@panic : column -a dist < tab | compute 'dist = sqrt(X*X+Y*Y)'
    dist    X       Y       Z
    ----    -       -       -
    3.16228 1       3       4
    12.0416 8       9       0



[Previous] [Next] [Up] [Top] [Edit]