QA
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→

More Linux Commands & SysAdmin Interview Questions

Beginner LevelLinux Commands & SysAdmin

How do Linux File Permissions (chmod, chown, chgrp) work in Octal and Symbolic notation?

Beginner LevelLinux Commands & SysAdmin

What is the Linux Filesystem Hierarchy Standard (/bin, /etc, /var, /usr, /opt, /tmp)?

Beginner LevelLinux Commands & SysAdmin

What are File Descriptors (0=stdin, 1=stdout, 2=stderr) and Redirection (>, >>, 2>&1)?