Last updated
AWK Built-in Variables Reference
NR — current record (line) number
NF — number of fields in current record
FS — field separator (default: whitespace)
OFS — output field separator (default: space)
RS — record separator (default: newline)
$0 — entire current line
$1 — first field, $2 — second field, etc.
$NF — last field
Why Use the AWK Command Generator
- No AWK expertise needed — describe the task, get the command
- Covers common patterns — field extraction, filtering, aggregation, transformation
- POSIX compatible — commands work on Linux, macOS, and Unix systems
- Explained output — each command includes a comment explaining what it does
- Multi-file patterns — join, lookup, and cross-file operations
Use the AWK Command Generator at TechConverter.me to process text files, log files, and CSV data quickly without needing to memorize AWK syntax.
Examples
Example 1: Print Specific Columns from CSV
Task: Print columns 1 and 3 from a comma-separated file
Generated command:
awk -F',' '{print $1, $3}' file.csv
With custom output separator:
awk -F',' 'BEGIN{OFS="\t"} {print $1, $3}' file.csv
Print last column (NF = number of fields):
awk -F',' '{print $NF}' file.csv
Print all columns except the first:
awk -F',' '{$1=""; print $0}' file.csv
Example 2: Filter Lines by Pattern
Task: Print lines containing "ERROR"
awk '/ERROR/' logfile.txt
Task: Print lines where field 3 equals "FAILED"
awk -F',' '$3 == "FAILED"' data.csv
Task: Print lines where field 2 is greater than 100
awk -F',' '$2 > 100' data.csv
Task: Print lines matching multiple conditions
awk -F',' '$2 > 100 && $3 == "active"' data.csv
Example 3: Sum a Column
Task: Sum all values in column 4 of a CSV
Generated command:
awk -F',' '{sum += $4} END {print "Total:", sum}' data.csv
Calculate average:
awk -F',' '{sum += $4; count++} END {print "Average:", sum/count}' data.csv
Find maximum value:
awk -F',' 'NR==1{max=$4} $4>max{max=$4} END{print "Max:", max}' data.csv