Course / The terminal and the language
Peek at the top, bottom, and size of a log
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-01-head-tail-and-count-lines
cd 02-01-head-tail-and-count-lines
gonomicon submitGoal
Print three facts about the log file testdata/app.log: its first line, its last line, and how many lines it has.
Example
If the log held these three lines:
alpha
beta
gamma
your script would print:
alpha
gamma
3
Rules
- Edit
answer.sh. It is a plain text file of commands, one per line, run from top to bottom. - Print exactly three lines, in that order. The last one is only digits.
- Read the log with commands. Do not copy its lines into your script: the real checker runs your script on different logs too.
What you'll practice
head, tail, wc -l, and feeding a file in with <.
Run it
gonomicon fetch week-1/02-01-head-tail-and-count-lines
cd 02-01-head-tail-and-count-lines
gonomicon test
gonomicon submit
Hints
- Three commands, one per line: one for the top, one for the bottom, one to count.
head -n 1 FILEandtail -n 1 FILEprint one line each.wc -l < FILEprints just the number, with no file name.