Course / The terminal and the language
See what happened around a failure
How to fetch and submit this lab
Once: install the tool and connect your account.
curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon loginEach lab: download it, edit the file named in the instructions, then submit.
gonomicon fetch week-1/02-04-grep-context-around-errors
cd 02-04-grep-context-around-errors
gonomicon submitGoal
A single log line rarely explains a failure; the lines around it do. Show every line of testdata/app.log that contains timeout, together with the line just before and just after it.
Example
For this log:
start
timeout here
middle
more
end
your script prints:
start
timeout here
middle
(Lines not near a match are left out. If two groups of lines are separated by a gap, grep prints a -- line between them. Keep it.)
Rules
- Edit
answer.sh. Onegrepcommand is enough. - If nothing matches, print nothing.
What you'll practice
grep -C (context lines).
Run it
gonomicon fetch week-1/02-04-grep-context-around-errors
cd 02-04-grep-context-around-errors
gonomicon test
gonomicon submit
Hints
- One line of context on each side of a match is
-C 1. - grep prints
--between groups that are not next to each other. Leave it in. grep -C 1 "timeout" testdata/app.log