Course outline
Course / The terminal and the language

Peek at the top, bottom, and size of a log

Lab

How to fetch and submit this lab

Once: install the tool and connect your account.

curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon login

Each 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 submit

Go installed? gonomicon test runs the visible test on your computer first. Submitting also runs hidden checks on our server.

Goal

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

  1. Three commands, one per line: one for the top, one for the bottom, one to count.
  2. head -n 1 FILE and tail -n 1 FILE print one line each.
  3. wc -l < FILE prints just the number, with no file name.

Something wrong with this lesson? Report a problem