UnixDroid

Text · Linux command

awk command in Linux

What does awk do?

awk processes text column by column. awk '{print $1}' prints the first column; $NF is the last column.

awk [-F delim] 'program' [file]

Most useful options

OptionWhat it does
-Ffield separator
$1 … $NFfirst … last column
NRline number
/regex/ {print}only lines matching

awk examples

$ awk '{print $1}' access.log Try it ›

client IPs from a web log

$ awk -F, '{print $2}' data.csv Try it ›

second CSV column

$ awk '{print $NF}' file Try it ›

last column

In security work

awk turns messy logs into clean columns you can sort and count.

Questions about awk

How do I print a column in Linux?

awk '{print $2}' file prints the second column.