Built-in Variables in Awk
AS
Aman Saurav
8 min read
#scripting
#data
Power up your one-liners with built-in variables.
- NR: Number of Records (Line number)
- NF: Number of Fields (Columns in current row)
- FS: Field Separator
Example: Print lines longer than 80 characters (assuming space separated):
awk 'length($0) > 80' file.txt
Example: Print the last column of every row:
awk '{print $NF}' file.txt