>_ IzzyLab

Hands-on task

This task is step 3 of the course “First steps with text”

Leave only the settings in a config

easy~4 min

The config /root/data/shop.conf is overgrown with comments: the program skips lines that start with # — they're notes for humans. There's even an old setting that was commented out. There are no other # in the file.

Save to /root/active.conf only the settings in effect — every line except the comments, in the same order. Don't change shop.conf itself.

What you'll practise:
  • grep -v
  • comments in configs
  • quotes

Topic breakdown

The -v flag (invert) turns grep around: it prints the lines where the text was not found and skips the rest.

grep nologin /etc/passwd      # accounts that aren't allowed to log in
grep -v nologin /etc/passwd   # all the others

That's how you strip noise from a file: debug lines from a log, comments from a config. In Linux configs a comment usually starts with #. In the shell itself # also means "a comment follows", so if you're searching for this character, put it in quotes: '#'.

What's checked

  1. active.conf has no comments
  2. All the settings are there, in order

What it looks like