Practice: A Log Report
Pipelines in action.
Your manager wants a quick report from the server log. How many requests were there? Which pages had errors? And who had the most errors? Let's answer each one with a pipeline. Pause and try first.

- A report for your manager
- Three questions
- One pipeline each
Requests and error pages
First, WC dash L counts every request. Sixty. Then grep finds the errors, awk prints the page, which is the sixth field, and sort with uniq dash C counts each page. The home page had the most errors.
wc -l < logs/server.log 60 grep ERROR logs/server.log | awk '{print $6}' | sort | uniq -c 1 /cart 4 /home 2 /shop
Who had the most errors
Same idea, but with field four, the user. And a final sort dash RN puts the biggest first. Priya had four of the seven errors. That's someone to help. And we can save the whole report into a file with a redirect, to send to the manager.
grep ERROR logs/server.log | awk '{print $4}' | sort | uniq -c | sort -rn 4 priya 2 alex 1 jo grep ERROR logs/server.log | awk '{print $4}' | sort | uniq -c | sort -rn > report.txt
The pattern behind it
Almost every report like this follows the same steps. Filter the lines you care about, with grep. Pick the column, with awk or cut. Group and count, with sort and uniq dash C. Then rank the results, with sort dash RN. Learn this shape, and you can answer questions about almost any log.
| key | value |
|---|---|
| Filter | grep |
| Pick | awk / cut |
| Count | sort | uniq -c |
| Rank | sort -rn |
Summary
Filter, pick, count, rank. That one pipeline shape answers most questions about a log. Next, one more text challenge to finish this section.
Key takeaways- grep to filter
- awk to pick
- sort | uniq -c | sort -rn