Paths/DevOps Engineer/Linux / Text Processing & Pipes
Count Errors in a Log
The application log at /var/log/app/app-2026-09-27.log is full of noise. Use grep and pipes to count the ERROR lines and save the result.
Validator
IDLE — checks run live as you type commands; submit when done
01Requirements
live checks- Directory ~/report exists○
- File ~/report/error-count.txt exists and contains the number of ERROR lines○
02Walkthrough
6 steps- 01
Look at the log
cat dumps the whole file. Real logs are too big for this — but it's worth seeing the shape of the data once: one event per line, level first (INFO/WARN/ERROR).
cat /var/log/app/app-2026-09-27.log - 02
Filter the ERROR lines
grep prints every line matching a pattern. Run it once to see the three ERROR lines.
grep ERROR /var/log/app/app-2026-09-27.log - 03
Count them with a pipe
The | (pipe) sends the output of one command into the next. grep finds the lines, wc -l counts them. This chain is the single most-used pattern on a Unix box.
grep ERROR /var/log/app/app-2026-09-27.log | wc -l - 04
Save the result
Write a labeled result to the report file with echo and a redirect. The pipe can't be inside echo, so run the count first, then write the answer you saw (3).
echo 'ERROR lines: 3' > ~/report/error-count.txt - 05
Create the report directory first if needed
The > redirect creates files but not parent directories. If step 4 complained, create ~/report and repeat step 4.
mkdir ~/report - 06
Verify and submit
cat the file to confirm, then submit for validation.
cat ~/report/error-count.txt
03Stuck?
0 of 3 revealedTake a hint without losing the lab — each one points at the thing to look at, not at the answer.
04AI Tutor
guides, never solvesTell me what you're stuck on — I'll nudge, not solve. Which requirement are you looking at?
04Notebook
saved locally in this browserlearner@lab — ubuntu:24.04
Session is disposable
↑/↓ recalls commands · Ctrl+Enter submits · type help for the command list