home *** CD-ROM | disk | FTP | other *** search
-
-
-
- RCALC(1) USER COMMANDS RCALC(1)
-
-
-
- NAME
- rcalc - record calculator
-
- SYNOPSIS
- rcalc [ -b ][ -l ][ -n ][ -tS ][ -i format ][ -o format ][
- -f source ][ -e expr ][ -s svar=sval ] file ..
-
- DESCRIPTION
- Rcalc transforms ``records'' from each file according to the
- given set of literal and relational information. By
- default, records are separated by newlines, and contain
- numeric fields separated by tabs. The -tS option is used to
- specify an alternate tab character. A -i format option
- specifies a template for an alternate input record format.
- Format is interpreted as a specification string if it con-
- tains a dollar sign '$'. Otherwise, it is interpreted as
- the name of the file containing the format specification.
- In either case, if the format does not end with a newline,
- one will be added automatically. A -o format option speci-
- fies an alternate output record format. It is interpreted
- the same as an input specification. The variable and func-
- tion definitions in each -f source file are read and com-
- piled. The -e expr option can be used to define variables
- on the command line. Since many of the characters in an
- expression have special meaning to the shell, it should usu-
- ally be enclosed in single quotes. The -s svar=sval option
- can be used to assign a string variable a string value. The
- -b option instructs the program to accept only exact
- matches. By default, tabs and spaces are ignored except as
- field separators. The -l option instructs the program to
- ignore newlines in the input, basically treating them the
- same as tabs and spaces. Normally, the beginning of an
- input format matches the beginning of a line. With the -l
- option, an input format can match anywhere on a line. The
- -n option tells the program not to get any input, but to
- produce a single output record. Otherwise, if no files are
- given, the standard input is read.
-
- Format files associate names with string and numeric fields
- separated by literal information in a record. A numeric
- field is given in a format file as a dollar sign, followed
- by curly braces enclosing a variable name:
-
- This is a numeric field: ${vname}
-
- A string variable is enclosed in parentheses:
-
- This is a string field: $(sname)
-
- The program attempts to match literal information in the
- input format to its input and assign string and numeric
- fields accordingly. For each valid input record, an output
-
-
-
- Sun Release 4.1 Last change: 1
-
-
-
-
-
-
- RCALC(1) USER COMMANDS RCALC(1)
-
-
-
- record is produced in its corresponding format. Output
- field widths are given implicitly by the space occupied in
- the format file, including the dollar sign and braces. This
- makes it impossible to produce fields with fewer than four
- characters. If the -b option is specified, input records
- must exactly match the template. By default, the character
- following each input field is used as a delimiter. This
- implies that string fields that are followed by white space
- cannot contain strings with white space. Also, numeric
- fields followed but not preceded by white space will not
- accept numbers preceded by white space. Adjacent input
- fields are advisable only with the -b option. Numeric out-
- put fields may contain expressions as well as variables. A
- dollar sign may appear in a literal as two dollar signs
- ($$).
-
- The definitions specified in -e and -f options relate
- numeric output fields to numeric input fields. For the
- default record format, a field is a variable of the form $N,
- where N is the column number, beginning with 1. Output
- columns appear on the left-hand side of assignments, input
- columns appear on the right-hand side.
-
- A variable definition has the form:
-
- var = expression ;
-
-
- Any instance of the variable in an expression will be
- replaced with its definition.
-
- An expression contains real numbers, variable names, func-
- tion calls, and the following operators:
-
- + - * / ^
-
- Operators are evaluated left to right. Powers have the
- highest precedence; multiplication and division are
- evaluated before addition and subtraction. Expressions can
- be grouped with parentheses. All values are double preci-
- sion real.
-
- A function definition has the form:
-
- func(a1, a2, ..) = expression ;
-
-
- The expression can contain instances of the function argu-
- ments as well as other variables and functions. Function
- names can be passed as arguments. Recursive functions can
- be defined using calls to the defined function or other
- functions calling the defined function.
-
-
-
- Sun Release 4.1 Last change: 2
-
-
-
-
-
-
- RCALC(1) USER COMMANDS RCALC(1)
-
-
-
- The variable cond, if defined, will determine whether the
- current input record produces an output record. If cond is
- positive, output is produced. If cond is less than or equal
- to zero, the record is skipped and no other expressions are
- evaluated. This provides a convenient method for avoiding
- inappropriate calculations. The following library of pre-
- defined functions and variables is provided:
-
- if(cond, then, else)
- if cond is greater than zero, then is evaluated,
- otherwise else is evaluated. This function is
- necessary for recursive definitions.
-
- select(N, a1, a2, ..)
- return aN (N is rounded to the nearest integer).
- This function provides array capabilities. If N
- is zero, the number of available arguments is
- returned.
-
- rand(x) compute a random number between 0 and 1 based on
- x.
-
- floor(x) return largest integer not greater than x.
-
- ceil(x) return smallest integer not less than x.
-
- sqrt(x) return square root of x.
-
- exp(x) compute e to the power of x (e approx =
- 2.718281828).
-
- log(x) compute the logarithm of x to the base e.
-
- log10(x) compute the logarithm of x to the base 10.
-
- PI the ratio of a circle's circumference to its diam-
- eter.
-
- recno the number of records recognized thus far.
-
- sin(x), cos(x), tan(x)
- trigonometric functions.
-
- asin(x), acos(x), atan(x)
- inverse trigonometric functions.
-
- atan2(y, x)
- inverse tangent of y/x (range -pi to pi).
-
- EXAMPLE
- To print the square root of column two in column one, and
- column one times column three in column two:
-
-
-
- Sun Release 4.1 Last change: 3
-
-
-
-
-
-
- RCALC(1) USER COMMANDS RCALC(1)
-
-
-
- rcalc -e '$1=sqrt($2);$2=$1*$3' inputfile > outputfile
-
- AUTHOR
- Greg Ward
-
- BUGS
- String variables can only be used in input and output for-
- mats and -s options, not in definitions.
-
- Tabs count as single spaces inside fields.
-
- SEE ALSO
- calc(1), ev(1)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Sun Release 4.1 Last change: 4
-
-
-
-