Bird
0
0

Why does the command grep "^start" file.txt only match lines beginning with "start"?

hard🧠 Conceptual Q10 of 15
Bash Scripting - Text Processing in Scripts
Why does the command grep "^start" file.txt only match lines beginning with "start"?
A"^" matches the end of the line
B"^" means match any character
C"^" anchors the pattern to the start of the line
D"^" is ignored by grep
Step-by-Step Solution
Solution:
  1. Step 1: Understand regex anchors

    The caret ^ in regex means the pattern must start at the beginning of the line.
  2. Step 2: Confirm grep behavior

    grep uses regex, so ^start matches lines starting exactly with "start".
  3. Final Answer:

    "^" anchors the pattern to the start of the line -> Option C
  4. Quick Check:

    ^ means start of line in grep regex [OK]
Quick Trick: Use ^ to match start of line in grep patterns [OK]
Common Mistakes:
MISTAKES
  • Thinking ^ matches any character
  • Assuming ^ matches end of line
  • Ignoring regex anchors in grep

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes