![]() Tabular data handling toolkit |
conditional expressions
Conditional expressionsConditional expressions use a simple syntax made up of operators such as = and !=, operands, and logical connectors such as && and ||. Operands may be literal numeric, alphanumeric, or text string values, @variables, @data-fields, or functions . In scripts , literal string operands may be enclosed in double quotes ("). There is no concept of presidence in these expressions (other than left to right); parentheses cannot be used except within strings.
Examplescat mydata | recsel "@3 > 100" cat mydata | recsel -h "@id = 285B" cat mydata | recsel -h "@class in A,J,N" Here's a conditional expression for finding lastname beginning with Gr, Gu or Gy: @lastname inlike Gr*,Gu*,Gy* OperandsOperands may be
In
scripts
, literal alphanumeric, text string, or
commalist
operands may be enclosed in double quotes (");
no variable evaluation occurs inside quoted strings.
Comparison operators
Wild card matching: Wild card matching may be done using like. Wild card characters are * which matches any number of any character, and ? which matches a single instance of any character. This matching is case-insensitive.
Commalist operators: these take a commalist on the right side. By default, lists are delimited using commas. If this is not convenient, the list delimitation character may be changed using #control listsep .
Logical connectorsIndividual conditional expressions may be connected together using logical AND (&&) or OR (||). An entire expression may be negated by putting not: at the beginning of the expression.
Because parentheses may not be used to establish presidence
mixing AND and OR in the same expression requires care.
When the expression is parsed, it is first
split into OR terms, then each of the OR terms is split into AND terms.
For example: A = B and C = D or E = E of F = G would evaluate to true,
because it is interpreted as if it were written
(a = B and C = D) or (e = e) or (f = g).
It may be best to avoid mixing AND and OR in the same expression
and use multiple expressions instead.
Limitations and bugs
Because parentheses may not be used to establish presidence,
the mixing of AND and OR in the same expression is problematic (see above).
|
![]() Tabular data handling toolkit Copyright Steve Grubb |