Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
In awk, $1 refers to the first field of the current line.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $1 instead of $2 for the second field.
Using $0 prints the whole line.
✗ Incorrect
In awk, $2 refers to the second field and $3 refers to the third field.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using NF alone prints the number of fields, not the field value.
Using $-1 is invalid syntax.
✗ Incorrect
$NF in awk refers to the last field of the current line.
4fill in blank
hardFill 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'
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.
✗ Incorrect
The first field is $1 and the total number of fields is NF.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up $NF and NF.
Using $1 instead of $2 for the second field.
✗ Incorrect
The second field is $2, the last field is $NF, and the total number of fields is NF.