>_ IzzyLab

Hands-on task

This task is step 17 of the course “sed: the stream editor”

Clean up a config

medium~5 min

The file /root/messy.conf is cluttered: it has comment lines (starting with #) and blank lines. With a single sed invocation remove both, leaving only the meaningful configuration lines, and write the result to /root/clean.conf.

What you'll practise:
  • sed
  • multiple commands
  • ^ and $
  • deleting lines
  • config cleanup

Topic breakdown

sed can execute several commands in one pass — they are separated by a semicolon in a single expression or with several -e flags. Each class of unwanted lines is specified by its own address pattern with the delete command: comments are recognized by the start of the line (the ^ anchor) and the # character, while a blank line is when there is nothing between the start and end of the line. This way a single invocation cleans a config of clutter.

What's checked

  1. comments and blank lines removed
  2. meaningful lines preserved

What it looks like