>_ IzzyLab

Hands-on task

This task is step 8 of the course “First steps in Linux”

Pull the errors out of a log

easy~4 min

/root/logs/app.log mixes lines of different severity levels: INFO is an ordinary event, WARN a warning, ERROR an error. Collect every ERROR line (exactly like that, in capitals) into /root/errors.txt — in the same order as in the log, unchanged.

What you'll practise:
  • grep
  • searching text
  • letter case

Topic breakdown

grep is a line filter: it reads a file and prints only the lines where the given text was found, skipping the rest. The order of lines is kept.

grep root /etc/passwd     # lines that contain root
grep -i Root /etc/passwd  # the same, ignoring case

By default grep is case-sensitive: Error, error and ERROR are three different words. The -i flag turns that off. If the search text has spaces, put it in quotes.

What's checked

  1. File /root/errors.txt created
  2. errors.txt holds only ERROR lines
  3. All ERROR lines are there, in the original order and unchanged

What it looks like