delete lines with sed match a special regex

Thomas picture Thomas · May 30, 2012 · Viewed 29.9k times · Source

I try to delete all lines who beginn with some optional special chars followed by blubb:

thats the lines I wanna match:

#blubb
*blubb
-blubb
blubb

thats should do it, but dont work :(

sed "/^.?blubb$/d" -i special.conf  
sed "/^[#*-]?blubb$/d" -i special.conf  

Has somebody the right solution?

Answer

anubhava picture anubhava · May 30, 2012

Use this sed command:

sed -i.old '/^[#*-]\{0,1\}blubb/d' special.conf

OR

sed -i.old -E '/^[#*-]?blubb/d' special.conf

OR

sed -i.old -r '/^[#*-]?blubb/d' special.conf