sed is the Unix stream editor: a program that reads text line by line, applies a list of editing commands to each line, and writes the transformed text to standard output. Unlike the interactive line editor ed from which it descends, sed never stops to ask the user what to do next. You hand it a script of commands up front, and it runs through the whole stream non-interactively, which makes it ideal for use inside pipelines and shell scripts. It was written by Lee E. McMahon at Bell Labs and shipped with Version 7 Unix, whose manual page records its name plainly as “stream editor.”
The command everyone learns first is substitution. The GNU sed manual gives its syntax as s/regexp/replacement/flags: sed matches the pattern space against the regular expression, and if the match succeeds it replaces the matched text with the replacement. The familiar one-liner s/old/new/ swaps the first occurrence of “old” on each line; adding the g flag (s/old/new/g) replaces every occurrence. This single construct, multiplied across a file or a pipe, is how generations of programmers have done bulk find-and-replace.
sed inherited its pattern language from ed and grep, so it speaks regular expressions. The replacement text can reach back into the match: the manual notes that an unescaped & stands for the whole matched portion, and \1 through \9 refer to the text captured between the nth \( and \) group. With those backreferences a substitution can rearrange and reuse parts of what it matched, not merely delete or overwrite it.
Substitution is only the best-known of sed’s commands. The same script language can delete lines, insert and append text, print selected lines, and address commands to specific line numbers or to lines matching a pattern. Because sed is line-oriented and addresses work like filters, a short sed program can extract a range, drop comments, or normalize whitespace across an arbitrarily large input.
What makes sed durable is that it embodies the Unix philosophy directly: it does one thing, edit a text stream, and it reads and writes plain text so it composes with everything else. A pipeline can feed grep’s matches into sed for cleanup and on to another tool, with no program aware of the others. GNU sed, the implementation most Linux users run today, adds extensions such as case-insensitive (I) and multi-line (M) matching, but the core idea is unchanged from McMahon’s 1974 design.
For the canonical reference, see the GNU sed manual at gnu.org and the original Version 7 sed manual page preserved from the Unix sources.