sed is a command-line stream editor for filtering and transforming text.
Sed is a stream editor: it reads one line of input, performs editing commands, and moves on to the next line. It is inspired by ed, Unix's first text editor and was developed as an enhanced replacement of grep. sed
is a standard utility.
By far the most common usage of sed
is to perform a simple pattern replacement:
sed -e 's/pattern/replacement/g'
The small command set and tools like "addressing" (line filtering) allow for easy and compact, yet powerful manipulations. While sed
is Turing-complete and could theoretically be used for any complex tasks, it is not meant to be a programming tool. As soon as tasks like counting or column manipulation are involved, tools like perl or awk are likely a better choice.
External references
Further reading
- THE SED FAQ
- Is there a basic tutorial for grep, awk and sed?
- How to remove multiple lines per occurrence in a file?
- How to ensure that string interpolated into `sed` substitution escapes all metachars
- sed one-liner to delete any line that does not contain lowercase letters
- How to append end of every line with the line itself
- sed: get 2 lines from a single one
- Return only the portion of a line after a matching pattern
- Extracting a regex matched with 'sed' without printing the surrounding characters