Custom field separator
Use colon as field separator, print user and UID
awk -F: '{print $1, $3}' /etc/passwd
- tool
- awk15 commands
More awk commands
-
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)