sed is short for stream editor. It reads in a file (one line at a time), modifies the contents per your parameters, and then outputs.
A more simple description, it allows you to modify the contents of a file without you actually having to open it.
Basics
Our sample text file called hey.txt looks like this,
Hey, diddle, diddle, The cat and the fiddle, The cow jumped over the moon; The little dog laughed To see such sport, And the dish ran away with the spoon. Make sure to keep this file in your /opt/nursery/ directory.
Here a simple example of replacing the word cow with reindeer in the file hey.txt,
sed -i 's/cow/reindeer/' notes.txt
The -i signifies inline editing and also will have sed automatically creates a backup file.
Here is an often used example of escaping a the / (slash) reserved character within the single quote,
sed -i 's/opt\/nursery/var\/ryhme/' notes.txt # need to escape '/' since we are using it as a separator
However, sed permits any character other than backslash or newline to be used instead of the forward slash. For example, the above example may be rewritten as follows to avoid needing to escape the forward slashes (sometimes referred to as "picket fences"):
sed -i 's,original/path,new/path,' notes.txt # do not need to escape '/' since we are using ',' as a separator
Insert Multiple Lines from File with Match
..
sed '/cdef/r muliple-lines.txt' notes.txt
..
References
Simple introduction - http://www.grymoire.com/Unix/Sed.html
Another introduction - http://lowfatlinux.com/linux-sed.html
Using sed to edit and save to the same file - http://unstableme.blogspot.ca/2010/01/sed-save-changes-to-same-file.html