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
Linux CLI - Text Processing
Which of the following is the correct syntax to search for the word error in a file named log.txt using grep?
Agrep log.txt error
Bgrep -f error log.txt
Cgrep error log.txt
Dgrep -e log.txt error
Step-by-Step Solution
Solution:
  1. Step 1: Recall grep syntax

    The basic syntax is grep [pattern] [file]. So to search for 'error' in 'log.txt', use grep error log.txt.
  2. Step 2: Analyze 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 incorrect flags.
  3. Final Answer:

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

    grep pattern file = grep error log.txt [OK]
Quick Trick: Use grep pattern filename order to avoid errors [OK]
Common Mistakes:
  • Swapping pattern and filename positions
  • Using -f flag incorrectly for pattern string
  • Confusing -e flag usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes