Arithmetic expressions in cdx
support the math.h
part of the C
standard library. That is, you get constants such as M_SQRT2
and functions such as hypot
. Only the function that return a single floating point number are supported, e.g. not sincos
Unary Operators : Leading +
and -
as well as trailing !
(factorial)
Binary Operators : The usual +,-,*,/,%
as well as ^ (power) and the comparison operators <,<=,>,>=,==,!=
which produce 0.0
if false and 1.0
if true.
- abs() - alias for fabs()
- min - takes any number of arguments (at least one) and returns the minimum
- max - takes any number of arguments (at least one) and returns the maximum
- avg - takes any number of arguments (at least one) and returns the average
- if - takes 3 arguments. If the first is non-zero, returns the second, else returns the third.
You canprovide parameters to a function by using a ColumnSet within square brackets. For example max([1-10,~5])
returns the maximum of the first ten columns, except ignoring column 5.
Expressions are used throughout the cdx tools
- Comparators : e.g.
cdx sort -k ',expr,sin(angle)'
sorts a file by the sin of the value of the 'angle' field. - Matchers : e.g.
cdx cgrep -p ',expr,price*quantity > 100.0'
selects the line where theprice
column multiplied by thequantity
column is greater than 100.