awk(Text Processing and Pattern Scanning Language) is a powerful language used for text processing and pattern scanning. It’s like a Swiss Army knife for text manipulation – you can use it to search, filter, and modify data, often in columns or structured data, making it ideal for analyzing files like logs or CSVs.
$ (field reference): Refers to individual fields in the input (e.g., $1, $2).
Example 2:
-zsh
> echo "apple orange banana" | awk '{print $2}'
orange
NR
NR (Number of Records): Refers to the number of lines processed.
In the example below, NR specifies that only the second line should be processed, and the action prints the first field ($1) of the selected line, where fields are separated by whitespace by default.