this is obsolete doc -- see http://doc.nethence.com/ instead

regex and sed examples 

 

 

Zero to one time low characters, 

[a-z]\{0,1\}

 

One or more time low characters, 

[a-z]\{1,\}

 

Anything but a dash, 

[^-]

 

Remove UNIX comments, 

  sed -e '
    /^#/d;
    /^$/d;
    /^ *#/d;
    /^  *#/d;
    '

Note. with GNU sed you can use '[[:space:]] instead of the space and tab lines, 

sed '/^[::space::]*#/d; /^$/d;' httpd.conf.dist > httpd.conf

 

Remove PHP comments, 

sed '/\/\*/,/*\//d; /^\/\//d; /^$/d;'

 

To convert URLs to HTML links, 

s|http: //\([a-zA-Z0-9.\,:\/?\&=~%+_#-]*\)|<a href=\"http: //\1\">\1</a>|g; 

s|https: //\([a-zA-Z0-9.\,:\/?\&=~%+_#-]*\)|<a href=\"https: //\1\">\1</a>|g; 

s|ftp: //\([a-zA-Z0-9.\,:\/?=\&~%+_#-]*\)|<a href=\"ftp: //\1\">\1</a>|g; 

 

Print first line until "match" gets reached, 

sed -n '1,/match/p'

print from "match" until the end of file gets reached, 

sed -n '/match/,$p'

 

Print lines matching both match1 and match2 in the same line, 

sed -ne /match1/{/match2/p;}

print the lines machine either match1 or match2, 

grep -E 'match1|match2'

 

 

References 

http://www.gnu.org/software/sed/manual/html_node/Regular-Expressions.html 

http://sed.sourceforge.net/sed1line.txt 

http://sed.sourceforge.net/sedfaq.html 

http://www.gnu.org/software/sed/manual/sed.html 

http://www.grymoire.com/Unix/Sed.html#uh-0 

http://bash-hackers.org/wiki/doku.php?id=howto:edit-ed 

http://www.epons.org/sed.php