What is sed?
sed is a stream-editor. sed can manipulate text streams or files by e.g. inserting or deleting lines and text substitution. Text substitution searches for a given pattern and replaces it with a given piece of text. Because in UNIX, streams are files, you can use sed for automated file editing as well. Let's just consider files for the rest of this page.
The generic way to use sed is:
sed [options] 's/pattern/replacement/flags' <input>
where input is a text file.
A useful option to handle with care is -i which makes sed edit files in-place, meaning the original input file is modified. Be careful not to lose your source files! See sed's manpage for creating a backup.
Two useful flags are 'g' which applies the expression to the entire line, and 'i' which does case insensitive matching.
Examples
sed 's/something/anything/' something.txt
This replaces one something in every line
sed 's/something/anything/g' something.txt
This replaces every something in every line
sed 's/^/pre_/' input.txt | sed 's/$/_post/'
This inserts pre_ before and _post at the end of every line. ^ indicates
the start of a line, where $ indicates the end of a line.