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.
cat
.
sed -i
.
g
flag.
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.
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).