Bird
0
0

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

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

    The basic syntax is: grep [pattern] [file]. So to find "hello" in file.txt, use grep hello file.txt.
  2. Step 2: Check other options

    -f expects a file with patterns, -x matches whole lines, but order matters; options A and D have wrong argument order.
  3. Final Answer:

    grep hello file.txt -> Option A
  4. Quick Check:

    Basic grep syntax = grep pattern file [OK]
Quick Trick: grep syntax: grep pattern filename [OK]
Common Mistakes:
MISTAKES
  • Swapping pattern and filename
  • Using -f without a pattern file
  • Misusing -x option

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes