Frequently Asked Question

What does sed actually do, and why is it called a stream editor?

sed reads its input one line at a time, applies a small program of editing commands to each line, and writes the result to standard output. It is non- interactive (unlike vi or nano) and works as a filter in a pipeline, hence stream editor. Its commonest use is search-and-replace: sed 's/foo/bar/g' substitutes every occurrence of foo with bar. The s is for substitute, the trailing g is for global (replace all matches on each line, not just the first).

sed can also delete lines (/^#/d deletes comments, 5,10d deletes lines 5–10), print selectively (with -n and p), and address commands by line number or regex. Its addressing language is what makes it more than a glorified search-and- replace: you can run different transformations on different parts of the file in a single pass. For large files this matters, sed keeps only one line in memory at a time, so it scales to gigabytes without flinching.

Further reading and video