Join David D. Levine for an in-depth discussion in this video What is sed?, part of SED Essential Training.
- So, what is sed, anyway? Where did it come from? Where is it available? What is it good for? And, What is it not so good for? As to, where did it come from, sed, the name is short for stream editor, was first built back in 1973 by Lee E. McMahon at Bell Labs as a command-line version of the interactive text editor ed. Like grep, sed was designed to made some of the text editing capabilities of ed available for the use on the command line, and in shell scripts.
Seds syntax, and its use of regular expressions, have influenced many later programs, including awk, python, and perl. Where is sed available? You'll find sed preinstalled on most UNIX variants, including Mac OS X. Just open a command line terminal and type sed and you're good to go. If sed is not preinstalled on your system, you may be able to download it as an install package. To use sed under Windows, you can install Cygwin, which provides a complete UNIX style shell environment, or, UnxUtils, which provides individual UNIX tools that run directly at the Windows command prompt.
Note that there is no I in the UnxUtils http URL. Both of these are free. But many other alternatives, both commercial and open source, are available. What is sed good for? Sed is great for performing simple manipulations on line-oriented text files, such as replacing certain strings with other strings within a line. Or adding, removing, or swapping entire lines. It's most often used as a filter to perform some transformation on data being output by one program before its used by another.
And appears often in shell scripts. Many useful sed programs can be written with just a few characters on the command line. But you can also write complex sed programs and store them in a file, for later, or repeated use. And what is sed not so good for? Sed is not useful for manipulating binary data, such as image files and spreadsheets. Although, if you can export such data into text format, you may find sed useful.
- Understanding input, output, files, and pipes
- Modifying the "s" command
- Using character classes and quantifiers
- Controlling printing
- Reading and writing files
- Appending, inserting, and editing entire lines
- Writing programs in SED
- Using advanced programming commands