What Is sed and How Does It Work? (Stream Editor)
sed (stream editor) transforms text non-interactively based on a set of rules, most commonly for search-and-replace.
Published September 30, 2026
sed (stream editor) transforms text non-interactively based on a set of rules, most commonly for search-and-replace.
Key points
- sed 's/old/new/' file.txt replaces the first occurrence of "old" with "new" on each line
- Add the g flag — s/old/new/g — to replace every occurrence on each line, not just the first
- sed -i edits the file in place instead of only printing the result to standard output
Example
sed -i 's/foo/bar/g' config.txt