CSVfox
Leverage Your Data.
 English

Filtering and Command Conditions

Conditions for filtering and executing commands

There are two application areas for the use of conditions:

  • As a criterion for filtering data rows at input or output time, see ±filter.
  • As a prerequisite for the execution of commands, see ±if/else/end.

All filtering and condition evaluating is field-based. It takes place line by line according to the general mode of operation of CSVfox, and is always based on the current data of the actual line.

Some filter examples

+filter[3]
Only reads and processes this data row if the third column is not empty.
-filter[Status]!={Locked}
Only outputs the current data row if the column "Status" is not equal to "Locked".
-filter[Fruit]={Apple}/{Pear}
Only outputs the current data row if the text in column "Fruit" equals either "Apple" or "Pear".
-filter(NumericExpression1)>(NumericExpression2)
Only outputs the current data row if NumericExpression1 is larger than NumericExpression2.
"NumericExpression1" and "NumericExpression2" are calculated before comparison takes place.

Some conditional command examples

-if["Not in Navigation"]=Yes//set[*]=1//else//set[*]=0
If the field "Not in Navigation" contains the value "Yes", sets it to "1", otherwise to "0".
-if[ThisField]={Expression}//set[ThatField]=Yesvalue//else//set[ThatField]=Novalue
Inserts in column [ThatField] either "Yesvalue" or "Novalue", if column [ThisField] matches "Expression", else if not.
"Expression", "Yesvalue" and "Novalue" are resolved. For the conditions see below.
-if(NumericExpression1)>=(NumericExpression2)//set[Field]=1//else//set[Field]=2
In column [Field], this inserts either "Yesvalue" or "Novalue" if "Expression1" is greater or equal to "Expression2", else if not.
"Expression1", "Expression2", "Yesvalue" and "Novalue" are resolved.

Condition Operands and Operators

Operands

An operand can be a single literal CSV field [Field], a numeric CSV field ([Field]), a literal string or an expression {Expression}, or a numeric expression a or formula (Expression).
So there is always some kind of brackets around any operand.
Before evaluating the condition, all fields are replaced by their actual values, all formulas are calculated, and all expressions are resolved.

In the following table, "{Opn}" stands for an operand of any kind, be it a single field, or of numeric, literal string, or expression type.
{Op1} = left operand
{Op2} = right operand
{Op3} = another right operand 

Available Condition Operators

Function Operator Alternative
Operator
String Numeric Number of
Right Operands
Syntax
not empty 0 {Op1}
empty ! = 0 {Op1}!
equal e = 1 * {Op1}={Op2}
greater g > 1 * {Op1}>{Op2}
lesser l < 1 * {Op1}<{Op2}
greater or equal ge >= 1 * {Op1}>={Op2}
lesser or equal le <= 1 * {Op1}<={Op2}
begins with b <# 1 * {Op1}<#{Op2}
finishes with f #> 1 * {Op1}#>{Op2}
contains c <#> 1 * {Op1}<#>{Op2}
regular match r @ 1 * {Op1}@{Op2}
greater than op1,
and lesser than op2
gl <> 2 {Op1}<>{Op2}/{Op3}
greater/equal to op1,
and lesser/equal to op2
gel <=> 2 {Op1}<=>{Op2}/{Op3}
lesser than op1,
or greater than op2
lg >< 2 {Op1}><{Op2}/{Op3}
lesser/equal to op1,
or greater/equal to op2
leg >=< 2 {Op1}>=<{Op2}/{Op3}

* more operands can be used when concatenating them with delimiters, see below

Negation

All operators can also be used in a negated way.
Negations is expressed by prepending a"!" or a "-" before the operator.
So "=" or "e" means "equal", while "!=" or "!e" means "not equal".
A hyphen "-" can also be used in place of an exclamation mark "!", if the command line or script causes trouble with the latter.

In many cases, a negated operator is equivalent to another non-negated operator.
So, the negation of ">" (greater) is "!>" (not greater), which is equivalent to "<=" (lesser or equal).
But this does not apply to the literal operators "b" (begins with), "c" (contains), and "f" (finishes with); here the negation "!b" means "does not begin with", "!c" means "does not contain", and "!f" means "does not end with".
Also the regular match "r" can be negated with "!r", which then means "does not match".

However, there is still an important difference when it comes to more than one operand on the right side.

Concatenated right operands

In all conditions when there is one right operand required, there can be used more right operands, concatenated with a delimiter (generally a "/").
In this case, the following applies:

  • Multiple positive choices are OR-ed,
  • Multiple negated choices are being AND-ed.
  • If there is an "empty" choice, place it first, so that the choices list seems to start with a delimiter.
Do not forget to "escape" all brackets that are not a grammatical part of a field identifier, formula or formatting expression, i.e. replacing all literal (, ), [, ], {, }, <, > characters with \(, \), \[, \], \{, }, \<, or \>.

See this example with a filter condition that means "contains":
-filter[Field]c{abc} [Field] contains "abc".
-filter[Field]c{abc}/{def}/{ghi} [Field] contains "abc" or "def" or "ghi".
-filter[Field]!c{abc}/{def}/{ghi} [Field] does not contain "abc" and also not "def" and also not "ghi"
(i.e., nor "abc" neither "def" neither "ghi").
filter/:[Field]!c{abc}:{def}:{ghi} The same as above, but with a changed separator (":" instead of "/")


For strings, the "i" mode sets the conditions to not case-sensitive

For  case-insensitive comparisons, the "i" mode can applied in two ways:

-filter[Field]={expression} [Field] and {expression} are equal.
-filter/i[Field]={expression}
-filter[Field]i={expression}
[Field] and {expression} are equal, comparison is not case-sensitive.
-filter[Field]!=[Another Field] [Field] and [Another Field] are not equal.
-filter/i[Field]!s[Another Field]
-filterField]!i=[Another Field]
 
[Field] and [Another Field] are not equal, comparison is not case-sensitive.

Under construction, coming soon