Bird
0
0

Which of the following is the correct syntax to print the second field of a space-separated text file using awk?

easy📝 Syntax Q3 of 15
Linux CLI - Text Processing
Which of the following is the correct syntax to print the second field of a space-separated text file using awk?
Aawk '{print 2}' filename
Bawk 'print $2' filename
Cawk '{print $2}' filename
Dawk '{print $}' filename
Step-by-Step Solution
Solution:
  1. Step 1: Understand awk field syntax

    In awk, fields are accessed with $ followed by the field number inside braces and quotes.
  2. Step 2: Check syntax correctness

    awk '{print $2}' filename correctly uses '{print $2}', others miss braces or use wrong syntax.
  3. Final Answer:

    awk '{print $2}' filename -> Option C
  4. Quick Check:

    Correct awk field print syntax = C [OK]
Quick Trick: Use single quotes and braces: awk '{print $2}' [OK]
Common Mistakes:
  • Omitting braces around print statement
  • Using print without $ for field number
  • Missing quotes around awk program

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes