Course outline
Course / The terminal and the language

Filter out noise and search whole trees

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-03-grep-invert-recursive-extended
cd 02-03-grep-invert-recursive-extended
gonomicon submit

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

Goal

The folder testdata/logs holds several log files in nested folders. Print every line that contains error or warn, except lines that also contain debug, sorted alphabetically.

Example

If testdata/logs/a.log held:

info fine
warn disk
debug warn ignored

your script prints (note the file name grep -r adds in front):

testdata/logs/a.log:warn disk

Rules

  • Edit answer.sh. Search the whole testdata/logs folder, including every sub-folder.
  • Keep the file-name prefix that grep -r prints. Do not remove it.
  • End your pipeline with sort so the lines come out in a fixed order.
  • Matching is case-sensitive: the words are lower-case in these logs.

What you'll practice

grep -r, grep -E, grep -v, pipes, and sort.

Run it

gonomicon fetch week-1/02-03-grep-invert-recursive-extended
cd 02-03-grep-invert-recursive-extended
gonomicon test
gonomicon submit

Hints

  1. grep -r searches every file inside a folder. -E lets you write error|warn.
  2. Chain two greps with a pipe: the first finds, the second removes lines with grep -v.
  3. Finish with | sort so the output order never changes.

Something wrong with this lesson? Report a problem