Bird
0
0

What happens if multiple patterns match the same line in an awk script with multiple pattern-action pairs?

hard📝 Conceptual Q10 of 15
Linux CLI - Text Processing
What happens if multiple patterns match the same line in an awk script with multiple pattern-action pairs?
AOnly the first matching action is executed
BThe last matching action is executed
CAll matching actions are executed in order
DThe script throws an error
Step-by-Step Solution
Solution:
  1. Step 1: Understand awk pattern-action processing

    Awk checks each pattern-action pair independently for every line.
  2. Step 2: Identify behavior when multiple patterns match

    All actions for matching patterns run in the order they appear.
  3. Final Answer:

    All matching actions are executed in order -> Option C
  4. Quick Check:

    Multiple matches trigger all actions [OK]
Quick Trick: All matching actions run, not just first [OK]
Common Mistakes:
  • Thinking only one action runs per line
  • Expecting error on multiple matches
  • Confusing awk with other languages' switch behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes