Skip to content
Justice Tech School

awk Processes Columns

awk splits lines into fields $1 $2 and runs actions. -F sets the separator, NR is the line number and END runs after the last line.

Example
printf "Ada 90\nTunde 72\nZed 85\n" | awk '{ print $1 }'
printf "Ada 90\nTunde 72\nZed 85\n" | awk '$2 > 80 { print $1 }'
printf "Ada 90\nTunde 72\nZed 85\n" | awk '{ s += $2 } END { print s, s / NR }'
echo "a,b,c" | awk -F, '{ print $2 }'

Result

Ada
Tunde
Zed
Ada
Zed
247 82.3333
b

Exercise

First field.

awk '{ print  }'

Quiz Test

What is NR in awk?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.