You have access logs from five web servers and need one timeline sorted by time. How?
IntermediateScenarioScenarios: text processing and scheduling decisions
Answer
Situation read → Each file is already sorted, so merge rather than re-sort, and tag lines with their source.
What I'd do →
- If logs use ISO 8601 timestamps at line start, a merge sort is enough:
for h in web{1..5}; do ssh -n "$h" 'cat /var/log/app/app.log' | sed "s/^/$h /" > "/tmp/$h.log"; done sort -m -k2,2 /tmp/web*.log > timeline.log - For Nginx's
[09/Nov/2026:14:23:01 +0000]format, convert to a sortable key first (epoch via gawkmktime), then sort numerically. - Make sure clocks were synchronized, or the merged timeline lies.
Why → sort -m is linear on pre-sorted input; ISO timestamps sort correctly as strings.
Interview tip → Say this is the argument for ISO 8601 UTC timestamps everywhere and for central logging.
More on Scenarios: text processing and scheduling decisions
Users report errors in the last hour. From the Nginx access log, find which endpoints produce the most 5xx responses.BeginnerA MySQL slow log is 3 GB. You need the 10 slowest query patterns. What do you do?IntermediateTwo servers that should be identical behave differently. Compare their installed packages.BeginnerFind which pods were OOMKilled in a namespace, with their container names and restart counts.IntermediateProduce a CSV of running EC2 instances that are missing an `Owner` tag.IntermediateA vendor needs application logs, but they contain emails and card numbers. Mask them first.Intermediate