Bird
0
0

Identify the error in this awk command:

medium📝 Debug Q14 of 15
Linux CLI - Text Processing
Identify the error in this awk command:
awk '$1 == "apple" print $2' file.txt
AIncorrect field number
BWrong comparison operator
CMissing braces {} around action
DQuotes around apple should be single quotes
Step-by-Step Solution
Solution:
  1. Step 1: Check awk syntax for pattern and action

    Awk requires actions to be inside braces {} after the pattern.
  2. Step 2: Identify missing braces

    The command misses braces around 'print $2', causing syntax error.
  3. Final Answer:

    Missing braces {} around action -> Option C
  4. Quick Check:

    Actions need braces {} [OK]
Quick Trick: Always put actions inside {} in awk [OK]
Common Mistakes:
  • Omitting braces around actions
  • Using wrong comparison operators
  • Misquoting strings inside patterns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes