Selecting Data Fields and Comparisons
- Data fields are denoted by a dollar sign($) and the number of the field.$1 is field one, $2 is field two, and so on. $0 represents the entire data line.
- Comparisons can be done with the relational operators: =, !=, <, >, <= and >= .
AWK Example (awk_prog3)
Variables
- Variable names must be made up of alphanumeric or underscore characters.
- A variable name can not start with a number.
- Variables in AWK do not use a dollar sign ($) like variables in bash.
- Variables do not require a formal declaration and often do not need to be initialized.
Built-In Variables
- NR Record (line) number
- NF Number of fields in current record(line)
- FS Field separator
- defaults to white space
- can be reset in your program
- can be set at run time with the -F option