Skip the header line

Process all lines except the first one (header)

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

tool
awk15 commands
tags
awklinux

More awk commands

  • awk '{count[$1]++} END {for (k in count) print count[k], k}' access.log | sort -rn

    Count how often each first field appears, for example IP addresses

  • awk '{print $NF}' file.txt

    NF is the number of fields, so $NF is the last field

  • awk '$2 > 500 && $5 == "POST"' access.log

    Print lines where field 2 is over 500 and field 5 is POST

  • awk '{printf "%-20s %5d\n", $1, $2}' data.txt

    Align output in fixed-width columns with printf

  • awk -f transform.awk input.txt

    Load the awk program from a separate file

all 15 awk commands