Quick awk cheat sheet.

Syntax

$ awk 'pattern { action }' file

Examples

  • get all lines containing string from file
    • awk '/foo/ { print $0 }' file

Cheat Sheet

  • -F<delimiter> to set delimiter of fields

Variables

valuefunction
$0full line
$1first field
$NFlast field
NRnumber of records
NFnumber of fields
OFSoutput field delimiter
FSinput field delimiter
ORSoutput record delimiter
RSinput record delimiter
FILENAMEname of file

Expressions

valuefunction
$1 == "value"first field equals a value
{print $1}print first field
NR == 1first record
{ print NR, $0}print line number and whole line
Last modified 2024.06.14