awk commands
15 commands, each with a one-line explanation. Click a command to copy it, or its title for details.
Commands 15 shown
-
awk '{print $3}' file.txtPrint the 3rd whitespace-delimited field
-
awk -F: '{print $1, $3}' /etc/passwdUse colon as field separator, print user and UID
-
awk '/ERROR/ {print NR": "$0}' app.logPrint line number and content for lines matching ERROR
-
awk '{sum += $4} END {print sum}' access.logAccumulate a numeric column and print total
-
awk '/START/,/END/' file.txtRange pattern: include lines from START to END inclusive
-
awk 'NR>1 {print $1, $2}' data.csvProcess all lines except the first (header)
-
awk '{count[$1]++} END {for (k in count) print count[k], k}' access.log | sort -rnFrequency count of the first field (e.g. IP addresses)
-
awk '{print $NF}' file.txtNF holds the number of fields; $NF is the last field
-
awk '$2 > 500 && $5 == "POST"' access.logPrint lines where field 2 > 500 AND field 5 is POST
-
awk '{printf "%-20s %5d\n", $1, $2}' data.txtAligned printf formatting with fixed column widths
-
awk -f transform.awk input.txtLoad awk program from an external script file
-
awk '{gsub(/foo/, "bar"); print}' input.txt > tmp && mv tmp input.txtGlobal substitution and write back to same file
-
gawk -v FPAT='([^,]+)|("[^"]+")' '{print $2}' data.csvParse quoted CSV fields correctly with FPAT in gawk
-
awk 'BEGIN{print "Start"} {lines++} END{print lines" lines processed"}' file.txtRun code before and after processing all lines
-
awk 'NR==FNR{a[$1]=$2; next} $1 in a {print $0, a[$1]}' lookup.txt data.txtLeft-join data.txt with lookup.txt on first field
no commands match — try a different search