Bird
0
0

Which of these is the correct syntax to print the first field of each line using awk?

easy📝 Syntax Q12 of 15
Linux CLI - Text Processing
Which of these is the correct syntax to print the first field of each line using awk?
Aawk '{print $}' file.txt
Bawk 'print $1' file.txt
Cawk '{print 1}' file.txt
Dawk '{print $1}' file.txt
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct awk print syntax

    The print statement must be inside braces {} and use $1 to refer to the first field.
  2. Step 2: Check each option

    awk '{print $1}' file.txt uses correct braces and $1. awk 'print $1' file.txt misses braces. awk '{print 1}' file.txt prints number 1 literally. awk '{print $}' file.txt uses invalid $.
  3. Final Answer:

    awk '{print $1}' file.txt -> Option D
  4. Quick Check:

    Print first field = awk '{print $1}' [OK]
Quick Trick: Always use braces {} around actions in awk [OK]
Common Mistakes:
  • Omitting braces around print
  • Using $ without field number
  • Printing literal numbers instead of fields

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes