Loading...

Lab 3: Basic sed Substitution

Correct a recurring configuration typo using a safe, repeatable sed substitution pattern. Preview the file, apply an in-place global replacement, then verify the result.

core troubleshooting services

Scenario

You’ve been handed a config file called webserver.conf with a typo. All instances of protcol need to be corrected to protocol . You are expected to use sed to fix it across the entire file in-place.

Operator context

This is a common system administration task: applying a safe text change across configuration files without opening an editor, then verifying the results immediately.

Objective

  • Preview a configuration file using cat .
  • Use sed to perform an in-place substitution across the file.
  • Verify the corrected contents after the change.

What You’ll Practice

  • Previewing config contents with cat .
  • In-place editing with sed -i .
  • Global substitutions using the g flag.
  • Verification loops: change, then re-check.

Walkthrough

Step 1 : Preview the contents of webserver.conf .
Command
cat webserver.conf

Confirm the typo exists before changing anything. This also lets you verify you are working in the right file.

server_name localhost;
protcol http;
listen 80;
protcol must be set correctly.
Step 2 : Replace protcol with protocol in-place across the file.
Command
sed -i 's/protcol/protocol/g' webserver.conf

This uses sed substitution syntax s/old/new/ and applies it globally on each line with g . The -i flag updates the file in-place.

Step 3 : Verify that the typo has been corrected.
Command
cat webserver.conf

Always re-check after an in-place edit to confirm you changed what you intended and nothing else.

server_name localhost;
protocol http;
listen 80;
protocol must be set correctly.

Reference

  • cat <file> : Prints file contents to standard output.
  • sed -i 's/old/new/g' <file> : Performs a substitution and writes changes back to the file.
    • -i : Edit the file in-place (modify the file directly).
    • s/old/new/ : Substitute the first match of old with new on each line.
    • g : Global replacement on each line (replace all matches on the line, not just the first).