Share this page

Operators

The following table provides the list of operators with examples.

Note: IFS is set to space for these examples.

OPERATOR | OPERATION | EXAMPLE ---------------------- | MEANING OF EXAMPLE | |

RESULTS | ||||

= += | assignment | a = 1; a += 2; | a is set to a + 2 | |

a now equals 3 | ||||

|| | logical OR | a || b | 1 if a or b is true, 0 otherwise | |

abc c ac bc | # true (1) # false (0) # true (1) # true (1) | |||

&& | logical AND | a && b | 1 if a and b are true, 0 otherwise | |

abc c ac bc | # true (1) # false (0) # false (0) # false (0) | |||

in | array membership | j in a | 1 if a[j] exists, 0 otherwise | |

a[b] = 4; a[c] = "dog"; j in a; a[j] = "cat"; j in a; | # false (0) # true (1) | |||

~ !~ | matching matched by not matched by | $1 ~ /go/ | 1 if the first field contains go, 0 otherwise | |

gone fishing will go fish | # true (1) # false (0) | |||

< <= == != >= > | relational less than less than or equal to equal to not equal to greater than or equal to greater than | a == b | 1 if a is equal to b, 0 otherwise | |

a = 1; b = 1; a == b; b = 5; a == b; | # true (1) # false (0) | |||

+ | concatenation | "A" + "BC" | If either variable is a string, variables are united side by side. | |

a = "A" + "BC" | a = "ABC" | |||

+ - | add subtract | a + b | If both variables are numeric, sum of a and b or difference between a and b. | |

a = 2; b = 1; c = a + b; c= a - b; | c equals 3 c equals 1 | |||

* / | multiply divide | a * b | product of a and b | |

a = 2; b = 3; c = a * b; | c equals 6 | |||

$ | field | $2+1 | value of the second field plus 1 | |

owe 25 dollars a = $2 + 1; | a equals 26 | |||

( ) | grouping and precedence | (AB) + C | 1 if both the characters in parenthesis are next to the other character and each other, 0 otherwise. |