S no | Statement | Description |
1 | If (pattern) statement else Statement | Typical if then else statement for Decisions |
2 | While (pattern) statement | Typical while statement for iteration. |
3 | For (Expression; pattern expression) statement. | Typical for statement for iteration.
|
4 | For (eliminate in array) statement | Typical for each statement for iteration through an array of items. |
5 | Break | Break statement to discontinue iteration continue statement skips current iteration, proceeds to the next iteration |
6 | Variable = Expression. | Variable assignment. |
7 | Print [List of expression] [<Expression]. | Print the list of expressions.
|
8 | Print f format [List of expressions][>Expression] | Provides formatted output the format is specified by a string. Variables can be placed inside of the format string that is replaced by the value of their corresponding expression. This is how the printf library function works in the C programing language and is similar to the formate function in scheme. |
9 | Next | Skip the remeding patterns on the current line of input |
10 | Exit | Skip the rest of the current line. |
11 | List of statement | Curly braces provide for nested statements. |
Variable | Function | Default |
FS | Input field separator | Space or tab |
RS | Input record separator | Newline |
OFS | Output field separator | Space or tab |
ORS | Output record separator | Newline |
NF | Number of nonempty fields in current record |
|
NR | Number of records read from all files |
|
FNR | File number of records read-record number in current file |
|
FILENAME | Name of the current file |
|
ARGC | Number of command-line arguments |
|
ARGV | Command-line argument array |
|
RLENGTH | Length of string matched by a built-in string function |
|
RSTART | Start of string matched by a built-in string function |
|
Operator | Example | Explanation |
*/%* | a^2 | Variable a is raised to power 2 (a2). |
++ | ++a a++ | Adds 1 to a. |
-- | --a a-- | Subtracts 1 from a. |
+- | a+b, a-b | Adds or subtracts two values. |
+ | +a | Unary plus: Value is unchanged. |
- | -a | Unary minus: Value is complemented. |
= | a=0 | a is assigned the value 0. |
*= | x*=y | The equivalent of x - x* y; x is assigned the product of x*y. |
/= | x/=y | The equivalent of x =x/ y; x is assigned the quotient of x/y. |
%= | x%=y | The equivalent of x = x % y where "%' is the modulo operator; x is assigned the modulus of x / y. |
+= | x+=5 | The equivalent of x = x + 5; x is assigned the sum of x and 5. |
-= | x-=5 | The equivalent of x = x - 5; x is assigned the difference (x - 5). |
Operator | Explanation |
< | Less than |
<= | Less than or equal |
== | Equal |
!= | Not Equal |
> | Greater than |
>= | Greater than or equal |
Operator | Explanation |
!expr | Not expression |
expr1 && expr2 | Expression 1 and Expression 2 |
expr1 || expr2 | Expression 1 or Expression 2 |