Print specific column

Print the 3rd whitespace-delimited field

awk '{print $3}' file.txt

tool
awk15 commands
tags
awklinux

More awk commands

  • awk -F: '{print $1, $3}' /etc/passwd

    Use colon as field separator, print user and UID

  • awk '/ERROR/ {print NR": "$0}' app.log

    Print line number and content for lines matching ERROR

  • awk '{sum += $4} END {print sum}' access.log

    Accumulate a numeric column and print total

  • awk '/START/,/END/' file.txt

    Range pattern: include lines from START to END inclusive

  • awk 'NR>1 {print $1, $2}' data.csv

    Process all lines except the first (header)

all 15 awk commands