Bird
0
0

Which bash command sequence efficiently extracts all lines containing the word error from system.log and writes them to error_report.txt?

hard🚀 Application Q8 of 15
Bash Scripting - Text Processing in Scripts
Which bash command sequence efficiently extracts all lines containing the word error from system.log and writes them to error_report.txt?
Ased 'error' system.log > error_report.txt
Bcat system.log | grep error > error_report.txt
Cgrep error < system.log >> error_report.txt
Dgrep 'error' system.log > error_report.txt
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct tool

    grep is the standard tool to search for patterns in files.
  2. Step 2: Use proper redirection

    Using > overwrites or creates the output file with matching lines.
  3. Step 3: Evaluate options

    grep 'error' system.log > error_report.txt uses grep directly with file input and output redirection, which is efficient and clear.
  4. Final Answer:

    grep 'error' system.log > error_report.txt -> Option D
  5. Quick Check:

    Direct grep with output redirection is simplest and fastest [OK]
Quick Trick: Use grep with output redirection, avoid unnecessary pipes [OK]
Common Mistakes:
MISTAKES
  • Using unnecessary cat before grep
  • Appending output instead of overwriting when not needed
  • Using sed incorrectly for simple pattern matching

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes