Generating A Report
Part of the Fundamentals section of Coddy's Terminal journey — lesson 52 of 82.
Challenge
EasyYou'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:
- First, write the text
=== Log Analysis Report ===toreport.txt - Append the text
Total errors found:followed by the error count (use a pipeline withgrepandwc -l) - Append the text
=== Error Details === - Append all the ERROR lines from
server.log
Then display the contents of report.txt using cat.
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.txtCongratulations! 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
grep "ERROR" server.log | wc -lAll lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective10Log Analyzer Project
Project OverviewViewing The Log File2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline