
- AWK Tutorial
- AWK - Home
- AWK - Overview
- AWK - Environment
- AWK - Workflow
- AWK - Basic Syntax
- AWK - Basic Examples
- AWK - Built in Variables
- AWK - Operators
- AWK - Regular Expressions
- AWK - Arrays
- AWK - Control Flow
- AWK - Loops
- AWK - Built in Functions
- AWK - User Defined Functions
- AWK - Output Redirection
- AWK - Pretty Printing
- AWK Useful Resources
- AWK - Quick Guide
- AWK - Useful Resources
- AWK - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
AWK - Relational Operators
AWK supports the following relational operators −
Equal to
It is represented by ==. It returns true if both operands are equal, otherwise it returns false. The following example demonstrates this −
Example
awk 'BEGIN { a = 10; b = 10; if (a == b) print "a == b" }'
On executing this code, you get the following result −
Output
a == b
Not Equal to
It is represented by !=. It returns true if both operands are unequal, otherwise it returns false.
Example
[jerry]$ awk 'BEGIN { a = 10; b = 20; if (a != b) print "a != b" }'
On executing this code, you get the following result −
Output
a != b
Less Than
It is represented by <. It returns true if the left-side operand is less than the right-side operand; otherwise it returns false.
Example
[jerry]$ awk 'BEGIN { a = 10; b = 20; if (a < b) print "a < b" }'
On executing this code, you get the following result −
Output
a < b
Less Than or Equal to
It is represented by <=. It returns true if the left-side operand is less than or equal to the right-side operand; otherwise it returns false.
Example
[jerry]$ awk 'BEGIN { a = 10; b = 10; if (a <= b) print "a <= b" }'
On executing this code, you get the following result −
Output
a <= b
Greater Than
It is represented by >. It returns true if the left-side operand is greater than the right-side operand, otherwise it returns false.
Example
[jerry]$ awk 'BEGIN { a = 10; b = 20; if (b > a ) print "b > a" }'
On executing the above code, you get the following result −
Output
b > a
Greater Than or Equal to
It is represented by >=. It returns true if the left-side operand is greater than or equal to the right-side operand; otherwise it returns false.
b >= a