Tools

AWK Cheat Sheet

Print-ready cheat sheet for AWK, organized for fast lookup, study, and desk-side use

Source
GNU AWK Manual (gnu.org/software/gawk)
License
MIT
Updated
2026-03-27

Sample

What's in this cheat sheet

  • Basics
  • Patterns & Actions
  • Variables
  • Fields
  • Control Flow
  • Functions
  • Arrays
  • String Functions
  • I/O
  • Common Patterns

Running AWK

awk '{ print }' file.txt          # print every line
awk '{ print $1 }' file.txt       # print first field
awk -F: '{ print $1 }' /etc/passwd  # custom delimiter
awk -f script.awk file.txt        # run from file
cmd | awk '{ print $2 }'          # pipe input

Program Structure

awk 'pattern { action }'Basic form — action runs when pattern matches
BEGIN { ... }Runs once before processing input
END { ... }Runs once after all input is processed
No patternAction runs for every line
No actionDefault action is `{ print }`

Download the full cheat sheet for all sections, formatted for print

Download PDF

Downloads

Choose the treatment that matches how you read