awk 'pattern {action}' file
$0
: Represents the entire current line.$1, $2, ...
: Represents the first, second, etc., fields in the current line.NF
: Number of fields in the current record.NR
: Number of the current record (line number).FS
: Field separator (default is space or tab).OFS
: Output field separator.RS
: Record separator (default is newline).ORS
: Output record separator.Use awk
to extract specific fields or columns from text files, such as log files or command outputs.
awk '{print $1, $3, $NF}' file.txt