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.
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.
This is a common system administration task: applying a safe text change across configuration files without opening an editor, then verifying the results immediately.
cat.sed to perform an in-place substitution across the file.sed substitution format: s/old/new/ applies per-line.
The g flag controls “all matches on the line.”
webserver.conf.
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.
protcol with
protocol in-place across the file.
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.
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.
You are not in the right directory or the filename is wrong. Confirm with
ls and re-run cat webserver.conf.
The match text may differ (case, whitespace, or a different typo). Use
grep -n protcol webserver.conf to confirm what is actually in the file.
The file may be owned by root or not writable. Check permissions with
ls -l and re-run the edit using sudo if appropriate.
This lab modifies a single file. Cleanup is returning the file to its starting state if needed.
# If you want to reset the file for another repetition, reintroduce the typo:
sed -i 's/protocol/protcol/g' webserver.conf
# Verify
cat webserver.conf
You can inspect, apply a targeted change, and verify results without relying on an interactive editor.
cat: Prints file contents to standard output.
cat <file>: Prints a file to standard output.
<file>: Path to the file to display.sed: Stream editor for transforming text.
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 old with new on each line (default is first match per line).g: Replace all matches on each line (not just the first).<file>: Target file to edit.