Bird
0
0

What does awk '{print $2}' file.txt do in a bash script?

easy🧠 Conceptual Q11 of 15
Bash Scripting - Text Processing in Scripts
What does awk '{print $2}' file.txt do in a bash script?
APrints the second word (field) from each line of file.txt
BPrints the entire line from file.txt
CPrints the first word (field) from each line of file.txt
DPrints the number of lines in file.txt
Step-by-Step Solution
Solution:
  1. Step 1: Understand awk field numbering

    Awk splits each line into fields separated by spaces by default. $1 is the first field, $2 is the second, and so on.
  2. Step 2: Analyze the command

    The command prints $2, which is the second field of each line in file.txt.
  3. Final Answer:

    Prints the second word (field) from each line of file.txt -> Option A
  4. Quick Check:

    Awk $2 prints second field [OK]
Quick Trick: Remember $1 is first field, $2 second, etc. [OK]
Common Mistakes:
MISTAKES
  • Confusing $2 with line number
  • Thinking it prints entire line
  • Mixing up field numbers starting at 0

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes