According to wikipedia, sed is a Unix utility that parses and transforms text, using a simple, compact programming language.
Examples
Modify an element inside files
For example, we modify each 011.html term by xperia_bouygues.html :
-i : edit files
s : substitution
user@host:~$ sed -i 's/011.html/xperia_bouygues.html/' *.html
Print file without comments
Regular expression ^ match expression at the start of a line. So here, every lines which begins with # character.
d ask sed to delete matched pattern
user@host:~$ cat myfile | sed '/^#/d'
Print file without blanks lines
Regular expression ^ match expression at the start of a line. $ match expression at the end of a line. So here blanks lines.
user@host:~$ cat myfile | sed '/^$/d'
Keep only lines with matching term
-i : edit files.
-n : silent mode
p : print matching terms
user@host:~$ sed -n -i '/vmail/p' /etc/courier/authlib/userdb/system
Delete carriage returns
:a : create a a label
N : concatenate (play s/\n//g)
$!ba : condition : while this is not the last line go back to label a.
user@host:~$ cat file | sed ':a;N;$!ba;s/\n//g'
Delete empty lines repetition
N : add next line to current pattern
s/^\n$// : do the substitution (replace carriage return by nothing)
P : print result
D : delete what left to avoid to print next line two times
user@host:~$ cat file | sed 'N;s/^\n$//;P;D'
Uppercase first letter of files names
\b : The word boundary \b matches positions where one side is a word character.
\b\(.\) : In a "illusions and witnesses.mp3" file it will match every first letter word. So in this example it will match : illusions and witnesses.mp3
\u\1 : \u will uppercase next char. So it will give : Illusions And Witnesses.Mp3
\b\(.\)\([a-z]* \) : Will prevent to match m of mp3. Because it will match only words separated by a space.
user@host $ for i in *mp3; do I=$(echo "$i" | sed -e "s/\b\(.\)\([a-z]* \)/\u\1\2/g" -e "s/ \(.\)\([a-z]*\).mp3/ \u\1\2.mp3/g"); mv "$i" "$I"; done