
- 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 - Ternary Operator
We can easily implement a condition expression using ternary operator. The following example demonstrates this −
Example
condition expression ? statement1 : statement2
When the condition expression returns true, statement1 gets executed; otherwise statement2 is executed. For instance, the following example finds the largest number from two given numbers.
Example
[jerry]$ awk 'BEGIN { a = 10; b = 20; (a > b) ? max = a : max = b; print "Max =", max}'
On executing this code, you get the following result −
Output
Max = 20
awk_operators.htm
Advertisements