Interactive sed command simulator. Part of the DevTools Surf developer suite. Browse more tools in the Developer Utilities collection.
Use Cases
Replace all occurrences of a string across a file in a single command.
Delete lines matching a pattern from a log file.
Insert or append text at specific line numbers in a file.
Chain multiple substitutions in a single sed command for batch text transformation.
Tips
Use -E flag (extended regex) for +, ?, and () without escaping — basic regex requires \+, \?, and \(\) which is easy to confuse.
Test destructive substitutions with p flag first: sed -n 's/old/new/p' shows what would change without modifying anything.
Use \n in replacement strings to insert literal newlines on GNU sed (macOS sed requires a different escape syntax).
Fun Facts
sed was created by Lee McMahon at Bell Labs in 1973, making it one of the oldest Unix utilities still in daily use. The name stands for 'stream editor.'
sed's s command (substitute) is the most used sed feature by far — many sed users have never needed any other command despite sed having a complete set of programming constructs.
POSIX standardized sed in 1992. GNU sed added extensions (like -E for extended regex and in-place editing with -i) that are not POSIX-compliant but became de facto standards.
FAQ
How do I do in-place file editing with sed?
Use sed -i 's/old/new/g' file.txt on GNU/Linux. On macOS (BSD sed), use sed -i '' 's/old/new/g' file.txt — the empty string after -i is required. Always backup before -i on critical files.
What's the difference between sed s/x/y/ and s/x/y/g?
Without /g, the substitution applies only to the first match on each line. With /g (global), it applies to every match on each line. This is the most common sed mistake.