
- 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 - Arithmetic Operators
AWK supports the following arithmetic operators −
Addition
It is represented by plus (+) symbol which adds two or more numbers. The following example demonstrates this −
Example
[jerry]$ awk 'BEGIN { a = 50; b = 20; print "(a + b) = ", (a + b) }'
On executing this code, you get the following result −
Output
(a + b) = 70
Subtraction
It is represented by minus (-) symbol which subtracts two or more numbers. The following example demonstrates this −
Example
[jerry]$ awk 'BEGIN { a = 50; b = 20; print "(a - b) = ", (a - b) }'
On executing this code, you get the following result −
Output
(a - b) = 30
Multiplication
It is represented by asterisk (*) symbol which multiplies two or more numbers. The following example demonstrates this −
Example
[jerry]$ awk 'BEGIN { a = 50; b = 20; print "(a * b) = ", (a * b) }'
On executing this code, you get the following result −
Output
(a * b) = 1000
Division
It is represented by slash (/) symbol which divides two or more numbers. The following example illustrates this −
Example
[jerry]$ awk 'BEGIN { a = 50; b = 20; print "(a / b) = ", (a / b) }'
On executing this code, you get the following result −
Output
(a / b) = 2.5
Modulus
It is represented by percent (%) symbol which finds the Modulus division of two or more numbers. The following example illustrates this −
Example
[jerry]$ awk 'BEGIN { a = 50; b = 20; print "(a % b) = ", (a % b) }'
On executing this code, you get the following result −
Output
(a % b) = 10