Bird
0
0

You want to print only the lines from file.txt where the second field is greater than 100 using awk. Which command achieves this?

hard📝 Application Q15 of 15
Linux CLI - Text Processing
You want to print only the lines from file.txt where the second field is greater than 100 using awk. Which command achieves this?
Aawk '{if $2 > 100 print $0}' file.txt
Bawk '$2 > 100 {print $0}' file.txt
Cawk '{print $0 if $2 > 100}' file.txt
Dawk '$2 => 100 {print $0}' file.txt
Step-by-Step Solution
Solution:
  1. Step 1: Understand condition syntax in awk

    Conditions go before the action block. The correct comparison operator is >, not =>.
  2. Step 2: Check each option

    awk '$2 > 100 {print $0}' file.txt uses correct syntax: $2 > 100 {print $0}. awk '{if $2 > 100 print $0}' file.txt misses parentheses and braces. awk '{print $0 if $2 > 100}' file.txt has wrong syntax. awk '$2 => 100 {print $0}' file.txt uses invalid operator =>.
  3. Final Answer:

    awk '$2 > 100 {print $0}' file.txt -> Option B
  4. Quick Check:

    Condition before action, use > operator [OK]
Quick Trick: Put condition before braces, use > not => [OK]
Common Mistakes:
  • Using invalid comparison operators like =>
  • Placing if inside braces without parentheses
  • Omitting braces or condition syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes