Foundation project

Project: summarize a log file

Lesson 11 of 20 · 15 min · Module 3: Text superpowers

Turn a raw log into a small report a teammate can read in seconds. This project combines folders, search, counting, and redirection.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Plan a report as a sequence of commands
  • Write counts and lines into files
  • Combine overwrite and append correctly

The idea

Real reports are built from small commands. Each command writes or appends one piece of the result to a file.

mkdir -p reports
grep WARN logs/app.log > reports/warnings.txt

01Plan the output first

Write down what each file must contain before you type. Then pick one command per piece: grep for lines, grep -c for counts, echo for fixed text.

02Build a file in steps

The summary starts with > (a fresh file with the title) and continues with >> (the count added under it). The order of these two commands matters.

echo "app.log report" > reports/summary.txt
grep -c ERROR logs/app.log >> reports/summary.txt
cat reports/summary.txt
Output
app.log report
3

03Check what you made

Finish with cat on each file. Reading your own output is how professionals catch a > that should have been >>.

Your project brief

Create a reports folder in your home folder and fill it with three files:
1) reports/errors.txt: every line of logs/app.log that contains ERROR (uppercase only).
2) reports/warn-count.txt: the number of lines that contain WARN.
3) reports/summary.txt: the line app.log report, followed by a line with the number of ERROR lines.

What the checks look for

  • errors.txt contains exactly the 3 uppercase ERROR lines
  • warn-count.txt contains 2
  • summary.txt has the title and the error count
  • Uses grep to build the report
Try it in the editor →

Take this with you

A report is a few small, checked commands writing to well-named files.

Go a little further

Add a fourth file listing the distinct ERROR messages with their counts.

Learn Linux Command Line for free

20 short lessons with real code and instant checks.

See the whole course →