Bird
0
0

Which of the following is the correct syntax to search for the word "error" in a file named log.txt using grep?

easy📝 Syntax Q12 of 15
Bash Scripting - Text Processing in Scripts
Which of the following is the correct syntax to search for the word "error" in a file named log.txt using grep?
Agrep -f error log.txt
Bgrep error log.txt
Cgrep log.txt error
Dgrep -c log.txt error
Step-by-Step Solution
Solution:
  1. Step 1: Identify grep syntax

    The correct syntax is grep [pattern] [file]. So, searching for "error" in "log.txt" is grep error log.txt.
  2. Step 2: Check other options

    grep -f error log.txt uses -f which expects a file of patterns, not a pattern string. Options C and D have arguments reversed or wrong flags.
  3. Final Answer:

    grep error log.txt -> Option B
  4. Quick Check:

    grep pattern file = correct syntax [OK]
Quick Trick: Remember: grep pattern filename [OK]
Common Mistakes:
MISTAKES
  • Swapping pattern and filename order
  • Using -f flag incorrectly
  • Confusing -c flag usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes