Was this helpful?
Comparison Expressions
comparison expression { statements }
Comparison expression patterns allow variable values to be compared with other variables, constants, or regular expressions.
Comparison expressions are composed of a variable followed by a comparison operator, followed by another variable, constant, or regular expression. They are used to test variable content in place of pattern matching. A simple variable or a comparison expression with a value of the null string "" or 0 evaluates to FALSE and with any other value evaluates to TRUE.
CXL Comparison Operators used in Comparison Expression Patterns
String Matching Operators
~ contains
!~ does not contain
Relational Operators
== is equal to
!= is not equal to
> is greater than
>= is greater than or equal to
< is less than
<= is less than or equal to
|| or
&& and
When using ~ and !~ string-matching operators, always code the constant regular expression on the right-hand side of the operator. For example, $0(1 6) ~ /word/ would match the literal "word" appearing within the first through sixth characters of the input line.
The logical operators | | and && are used to combine expressions and evaluate as follows:
Combination Expressions and Their Results
 
Expression
x | | y
x & & y
x is true
y is true
TRUE
TRUE
x is true
y is false
TRUE
FALSE
x is false
y is true
TRUE
FALSE
x is false
y is false
FALSE
FALSE
The && operator takes precedence over || when both are used in a single expression.
Example
There are 3 true results for the if statement below, $1, $2 and $3 both, and $4.
if ( $1 || $2 && $3 || $4 ) accept $*;
Last modified date: 12/03/2024