sed

# remove third line
sed -i 3d <filename>
 
# insert line on beginning of a file
sed -i '1i MY_TEXT' <FILE>
 
# String replace with sed
sed -i 's|STRING_FROM|STRING_TO|g' <FILE>
sed -i 's|[#]*param=[yes|no]*|param=yes|g' <FILE>
 
# add line to a file
sed -i '13i\YOUR_TEXT' <FILE>
 
# add line before last line
sed -i '$i test_line' <FILE>
 
# search block
sed -n '/FOO/,/BAR/p' <FILE>
 
# remove digits
echo ${FOO} | sed 's/[^0-9]*//g' 
 
# remove blanks (trim)
cat <FILE> | sed 's/  */ /g'
# remove blanks and tabs
cat <FILE> | sed "s/[ \t][ ]*/ /g"
# remove all blanks
cat <FILE> | sed -e 's/[\t ]//g;/^$/d'
cat <FILE> | sed -e 's/[\t]/ /g;s/  */ /g'
 
# write to file
sed 's/foot/bar/;w file'
 
# remove leading blank
sed "s/^[ ]*//"
 
# remove blank at end of line
sed 's/ *$//' file
 
# remove last comma
sed 's/,$/
 
# cat from to
sed -n '/^START/,/^END/p' <FILE>
 
# Uncomment all lines
sed -i 's/^/#/' /etc/locale.gen
 
# replace key = value
sed -i "s|^tag = .*|tag = ${NEW_VALUE}|g" <FILE>
 
# replace string
echo "my foo bar" | sed -e s/foo//
 
# uncomment line
sed -i '/foo/s/^#//g' <FILE>
sed -i '/foo/, +1 s/^#//g' <FILE>
 
# comment in line
sed -i '/foo/s/^/#/g' <FILE>
sed -i '/foo/, +1 s/^/#/g' <FILE>
 
# delete all input lines which are not followed by a line with matching string
sed '$!N;/\n.*foo/d;P;D'
 
# remove string between
sed 's/[_| ].*:/ /g'
 
# print last line
sed '$!d'