Bird
0
0

Why does awk '{print $NF}' file.txt print the last field of each line?

hard🧠 Conceptual Q10 of 15
Bash Scripting - Text Processing in Scripts
Why does awk '{print $NF}' file.txt print the last field of each line?
A<code>NF</code> is a built-in variable holding the number of fields in the current line
B<code>NF</code> is the first field of the line
C<code>NF</code> is the total number of lines in the file
D<code>NF</code> is a user-defined variable
Step-by-Step Solution
Solution:
  1. Step 1: Understand NF variable

    NF is a special awk variable that stores the number of fields in the current line.
  2. Step 2: Using $NF to print last field

    $NF accesses the field number equal to NF, which is the last field.
  3. Final Answer:

    NF is a built-in variable holding the number of fields in the current line -> Option A
  4. Quick Check:

    $NF prints last field [OK]
Quick Trick: Use $NF to print last field dynamically [OK]
Common Mistakes:
MISTAKES
  • Thinking NF is line count
  • Confusing NF with $1
  • Assuming NF is user variable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes