Tabular data handling toolkit  


Manual page for Conditional(expressions)

conditional expressions



Conditional expressions

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




Examples

cat 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*



Operands

Operands 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

= 	Equal to.  This is case sensitive for strings. 
!=	Not equal to. 
> 	Greater than.
>= 	Greater than or equal to. 
<  	Less than. 
<= 	Less than or equal to. 

If at least one operand is non-numeric, comparison operators such as > will do an ascii value comparison.

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.

like	Wild card match.  Example: hello like h* (true)
!like	Not a wild card match.

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 .

in	Member of list.  Example: z in x,y,z (true)
!in	Not a member of list. (Alt: ni)
inlike 	Same as in but wild card matching is used.
		(Wild cards may be used in list members.)
!inlike	Same as !in but wild card matching is used.



Logical connectors

Individual 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


Markup created by unroff 1.0,    September 19, 2003.