Sed (Stream EDitor) is a command line editor for POSIX environment. Sed processes one or more files according to an editing script and writes the results to standard output. Created at Bell Labs, it has been around since the mid-70s.
Sed (Stream EDitor) was created at Bell Labs by Lee McMahon in 1973 or 1974. It is one of the basic tools in the POSIX environment—it processes one or more files according to an editing script and writes the results to standard output.
Sed is normally required when the existing text file must be modified without user interactions by some script (bash
script, for instance). For instance, the commands
export ARG=17
sed "s/b/${ARG}/g" s.sh
will print the text of s.sh
where all occurrences of b
are replaced by the value of the environment variable ARG
, 17.
By default, sed prints to stdout
rather than overwriting the input file.
Popular questions
Some frequently asked Bash questions include:
- sed substitution with Bash variables
- Using different delimiters in sed commands and range addresses
- Combining two sed commands
- How to print lines between two patterns, inclusive or exclusive (in sed, AWK or Perl)?
- Non greedy (reluctant) regex matching in sed?
- Is it possible to escape regex metacharacters reliably with sed
- BSD/macOS Sed vs GNU Sed vs the POSIX Sed specification
Resources
External Resources
- GNU sed user's manual
- The Sed FAQ
- All Things Sed
- SED & Regular Expressions
- Turing machine simulator (Sed)
- Further Related Questions
- Sed One Liners
- Character Classes and Bracket Expressions
Free Sed Book
- Sed - An Introduction and Tutorial
- GNU sed one-liners - includes a chapter on regexp
Other Stack Exchange sites
- tagged sed on Unix & Linux
- tagged sed on Ask Ubuntu
- tagged sed on SuperUser
- tagged sed on Server Fault