0
0
Linux CLIscripting~5 mins

awk basics (field processing) in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does awk do in simple terms?

awk is a tool that reads text line by line and splits each line into parts called fields. It helps you pick and work with these parts easily.

Click to reveal answer
beginner
In awk, how do you refer to the first field of a line?

You use $1 to get the first field (like the first word) in the current line.

Click to reveal answer
beginner
What does $0 represent in awk?

$0 means the whole current line as it is, without splitting.

Click to reveal answer
beginner
How can you print the second and third fields of each line using awk?

Use awk '{print $2, $3}' filename. This prints the second and third parts of each line separated by space.

Click to reveal answer
beginner
What is the default field separator in awk?

The default separator is any space or tab. awk splits lines by spaces or tabs unless told otherwise.

Click to reveal answer
What does $3 represent in an awk command?
AThe third field of the current line
BThe whole line
CThe third line of the file
DThe number of fields in the line
Which awk variable holds the entire current line?
ANR
B$1
CFS
D$0
How does awk split fields by default?
ABy spaces or tabs
BBy commas
CBy semicolons
DBy new lines
What command prints the first and last fields of each line using awk?
Aawk '{print NF}' filename
Bawk '{print $0}' filename
Cawk '{print $1, $NF}' filename
Dawk '{print $2, $3}' filename
If a line has 5 fields, what does NF equal in awk?
A4
B5
C1
D0
Explain how awk processes a line and how you can access its parts.
Think about how a sentence breaks into words.
You got /4 concepts.
    Describe how to print specific fields from a file using awk.
    Imagine picking certain words from each line.
    You got /4 concepts.