Menu
Coddy logo textTech

Generating A Report

Part of the Fundamentals section of Coddy's Terminal journey. Lesson 52 of 82.

challenge icon

Challenge

Easy

You've analyzed the log file, filtered errors, and counted them. Now it's time to save your findings to a report file that can be shared or reviewed later.

Create a file called report.txt that contains a summary of the log analysis. Use redirection to write the following information to the file:

  1. First, write the text === Log Analysis Report === to report.txt
  2. Append the text Total errors found: followed by the error count (use a pipeline with grep and wc -l)
  3. Append the text === Error Details ===
  4. Append all the ERROR lines from server.log

Then display the contents of report.txt using cat.

Tip — Command Substitution: To embed the result of a command inside an echo string, use the $(...) syntax. For example:

echo "There are $(ls | wc -l) files here"

The shell runs the command inside $(...) first and replaces it with its output before passing the string to echo. You'll use this in step 2 to insert the error count directly into the line you write to the file:

echo "Total errors found: $(grep ERROR server.log | wc -l)" >> report.txt
echo "=== Log Analysis Report ===" > report.txt
echo "Total errors found: $(grep ERROR server.log | wc -l)" >> report.txt
echo "=== Error Details ===" >> report.txt
grep ERROR server.log >> report.txt
cat report.txt

Congratulations! You've completed the Log Analyzer Project. You've learned to view, filter, count, and report on log data using pipes and redirection - essential skills for any system administrator or developer.

Try it yourself

Terminal
grep "ERROR" server.log | wc -l

All lessons in Fundamentals

Practice on your own: Terminal playground