Print the last field

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

awk '{print $NF}' file.txt

tool
awk15 commands
tags
awklinux

More awk commands

  • 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

  • awk '{gsub(/foo/, "bar"); print}' input.txt > tmp && mv tmp input.txt

    Replace all matches and write the result back to the same file

  • gawk -v FPAT='([^,]+)|("[^"]+")' '{print $2}' data.csv

    Parse quoted CSV fields correctly with FPAT in gawk

all 15 awk commands