Bird
0
0

Which awk command prints the last field of each line in a file?

easy📝 Conceptual Q2 of 15
Linux CLI - Text Processing
Which awk command prints the last field of each line in a file?
Aawk '{print NF}' filename
Bawk '{print $NF}' filename
Cawk '{print $1}' filename
Dawk '{print $0}' filename
Step-by-Step Solution
Solution:
  1. Step 1: Identify how to print last field in awk

    The variable $NF refers to the last field of the current line.
  2. Step 2: Match command with correct syntax

    awk '{print $NF}' filename uses print $NF which prints the last field. Other options print first field, number of fields, or whole line.
  3. Final Answer:

    awk '{print $NF}' filename -> Option B
  4. Quick Check:

    $NF prints last field [OK]
Quick Trick: Use $NF to print last field dynamically [OK]
Common Mistakes:
  • Using $1 instead of $NF
  • Printing NF instead of field value
  • Printing $0 prints whole line, not last field

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes