Stream Editing with sed
Concept & Overview
Imagine you have a huge database dump file, and you need to replace all occurrences of an old server IP address with a new one. Opening it in an editor might freeze your computer. In Linux, we edit text streams on the fly using sed (short for "stream editor").
- The basic syntax is sed "s/old/new/g" file.txt to find and replace text.
- Adding the -i (in-place) flag saves the replacements directly back into the file itself, rather than just printing the modified text on screen.
Why this matters: If you run sed "s/port=80/port=8080/g" server.conf without -i, it will only print the modified text to your terminal screen. The actual file remains completely unchanged. The -i (in-place) flag is necessary to save the changes directly back into the file.
server.conf in your home folder. Change port=80 to port=8080 in-place by running sed -i "s/port=80/port=8080/g" server.conf.Command Syntax Reference
| Command / Syntax | Description |
|---|---|
sed -i "s/old/new/g" file | Perform in-place text replacement in a file |
Verification Objectives
These conditions will be automatically verified when you run commands inside the interactive terminal simulator:
- ○Use the "sed" command with -i flag
- ○Set port configuration to port=8080 in server.conf
Ready to complete Quest 108?
Test your skills live in the browser terminal with an emulated Linux filesystem, real-time command evaluation, and instant step-by-step hints.