0
0
Linux CLIscripting~10 mins

awk basics (field processing) in Linux CLI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print the first field of each line using awk.

Linux CLI
awk '{ print [1] }' file.txt
Drag options to blanks, or click blank then click option'
ANF
B$1
C1
D$0
Attempts:
3 left
💡 Hint
Common Mistakes
Using $0 prints the whole line instead of the first field.
Using NF prints the number of fields, not a field value.
2fill in blank
medium

Complete the code to print the second and third fields separated by a dash.

Linux CLI
awk '{ print [1]"-"[2] }' file.txt
Drag options to blanks, or click blank then click option'
A$2
B$3
C$1
D$0
Attempts:
3 left
💡 Hint
Common Mistakes
Using $1 instead of $2 for the second field.
Using $0 prints the whole line.
3fill in blank
hard

Fix the error in the code to print the last field of each line.

Linux CLI
awk '{ print [1] }' file.txt
Drag options to blanks, or click blank then click option'
A$NF
BNF
C$0
D$-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using NF alone prints the number of fields, not the field value.
Using $-1 is invalid syntax.
4fill in blank
hard

Fill both blanks to print the first field and the total number of fields separated by a space.

Linux CLI
awk '{ print [1], [2] }' file.txt
Drag options to blanks, or click blank then click option'
A$1
BNF
C$NF
D$0
Attempts:
3 left
💡 Hint
Common Mistakes
Using $0 instead of $1 for the first field.
Using $NF instead of NF for the number of fields.
5fill in blank
hard

Fill all three blanks to print the second field, the last field, and the total number of fields separated by commas.

Linux CLI
awk '{ print [1]","[2]","[3] }' file.txt
Drag options to blanks, or click blank then click option'
A$2
B$NF
CNF
D$1
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up $NF and NF.
Using $1 instead of $2 for the second field.