awk has several built-in variables that provide useful information during the processing of input data. Here are some of the commonly used built-in variables:
-
$0: Represents the entire current record (line).
-
$1, $2, ..., $n: Represents the individual fields in the current record, where
nis the field number. For example,$1is the first field,$2is the second field, and so on. -
NF: Stands for "Number of Fields" in the current record. It indicates how many fields are present in the current line.
-
NR: The total number of records processed so far (across all input files).
-
FNR: The number of records processed in the current input file.
-
FS: The input field separator, which defines how
awksplits input lines into fields. The default is whitespace. -
OFS: The output field separator, which defines how
awkseparates fields in the output. The default is a space. -
RS: The input record separator, which defines how
awksplits input into records. The default is a newline. -
ORS: The output record separator, which defines how
awkseparates records in the output. The default is a newline. -
ARGC: The number of command-line arguments passed to the
awkprogram. -
ARGV: An array containing the command-line arguments passed to the
awkprogram.
These variables can be very useful for manipulating and processing text data effectively in awk.
