Skip to content

Latest commit

 

History

History
29 lines (18 loc) · 1.48 KB

Expressions.md

File metadata and controls

29 lines (18 loc) · 1.48 KB

Arithmetic Expressions

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

Operators

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.

Additonal Functions

  • 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.

Column Set

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.

Uses

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 the price column multiplied by the quantity column is greater than 100.

home