Linux for Developers
/Advanced
sed
Definition
Stream Editor. A powerful utility that parses and transforms text. It is most commonly used for finding and replacing text across massive files or data streams without opening them in an editor.
Explain Like I'm New
The ultimate 'Find and Replace' tool. You can tell it 'Go into this 10,000 line file, find every instance of the word Apple, and change it to Orange instantly'.
Real World Example
You are deploying code and need to change the database IP from '127.0.0.1' to '192.168.1.5' inside a config file. You script it: `sed -i 's/127.0.0.1/192.168.1.5/g' config.txt`. The file is updated instantly.
Common Use Cases
- •Automated text replacement
- •Data sanitization
- •CI/CD scripting
Crucial Command Flags
| Flag / Option | Description |
|---|---|
| -i | In-place. Edit files directly instead of outputting to terminal. |
| -e | Expression. Add the script to the commands to be executed. |
| -n | Quiet. Suppress automatic printing of pattern space. |
Interview Questions
basic
- In the `sed` command `s/old/new/g`, what does the 's' stand for?
intermediate
- What does the `-i` flag do in a `sed` command?