Beginner LevelLinux Commands & SysAdmin
How do you perform basic text substitution using sed (Stream Editor)?
❓ Interview Prompt: Explain sed (Stream Editor), substitution syntax (s/search/replace/g), inline file editing (-i), and regex matching.
'sed' (Stream Editor) parses and transforms text streams line-by-line using script commands:
Substitution Syntax:
'sed "s/old_pattern/new_pattern/g" filename'
•
's': Substitute command.
•
'g': Global flag (replace all occurrences per line, not just the first).
•
'-i': Edit file in-place directly on disk!
Code Implementation Example
bash
# Preview text substitution without modifying file
sed 's/http://localhost/https://example.com/g' config.env
# Edit file in-place (-i) creating a backup file (.bak)
sed -i.bak 's/DB_HOST=127.0.0.1/DB_HOST=db.internal/g' .env💡Performing inline text substitution in config files using sed -i.
🎯 Interview Key Takeaway
Use sed -i 's/old/new/g' file to perform fast inline search-and-replace transformations in text files.
#sed#Stream Editor#Text Processing#Beginner
Back to all Linux Commands & SysAdmin Questions→