>_ IzzyLab

Hands-on task

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

Bulk replacement in configs

easy~3 min

The application is moving from port 8080 to 9090. In /etc/app/ there are several .conf files with the line listen 8080 — replace it in all of them with listen 9090, keeping backup copies alongside with the .bak extension (with the original content). The /etc/app directory is open in the Editor tab above the terminal — it's handy for comparing the configs and their copies before and after the replacement (do the replacement itself with sed).

What you'll practise:
  • sed
  • stream editing
  • s/// substitution
  • in-place editing
  • glob patterns

Topic breakdown

sed is a stream editor: it reads text line by line and applies commands, the most common of which is the substitution s/pattern/replacement/. By default sed writes the result to standard output without touching the file; to have the edits written back, there is the in-place flag -i, and a suffix appended to it makes it first save a backup copy of the original. A separate idea is not to list files by hand: the shell's glob pattern expands into the list of all matching paths, and a single command processes them all at once.

What's checked

  1. listen 8080 removed from all .conf files
  2. listen 9090 in every .conf file
  3. .bak copies with the original content exist alongside

What it looks like