Bird
0
0

What does the command awk '{print $1}' file.txt do in a bash script?

easy🧠 Conceptual Q1 of 15
Bash Scripting - Text Processing in Scripts
What does the command awk '{print $1}' file.txt do in a bash script?
APrints the last field of each line in file.txt
BPrints the entire line from file.txt
CPrints the first field of each line in file.txt
DPrints the number of lines in file.txt
Step-by-Step Solution
Solution:
  1. Step 1: Understand the awk print command

    The print $1 tells awk to print the first field of each line.
  2. Step 2: Apply to the file content

    For each line in file.txt, awk extracts and prints only the first word or field.
  3. Final Answer:

    Prints the first field of each line in file.txt -> Option C
  4. Quick Check:

    Field extraction = first field [OK]
Quick Trick: Use $1 for first field, $2 for second, etc. [OK]
Common Mistakes:
MISTAKES
  • Confusing $1 with entire line
  • Using print without $ sign
  • Assuming it prints last field

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes