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 'log.txt' error
Bgrep error log.txt
Cgrep -f error log.txt
Dgrep log.txt error
Step-by-Step Solution
Solution:
  1. Step 1: Identify grep command syntax

    The correct syntax is grep [pattern] [file].
  2. Step 2: Match pattern and file

    Here, error is the pattern and log.txt is the file to search.
  3. Final Answer:

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

    grep pattern file = correct syntax [OK]
Quick Trick: Remember grep syntax: grep pattern filename [OK]
Common Mistakes:
MISTAKES
  • Swapping pattern and filename
  • Using incorrect flags like -f
  • Putting filename before pattern

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes