Sed error "Invalid end of range"

I ran this substitution command on Ubuntu 12.04.

$ sed -e "s/([a-zA-Z0-9.-/\\ :]+)/\1/g" 

However, the following error occurs.

sed: -e expression # 1, char 27: Invalid end of range

I remember that the same expression works on MacOSX.
Can you describe why the team is not working?

+7
regex ubuntu sed substitution
May 19 '13 at 17:29
source share
1 answer

You can solve this in two ways. One of them is to use the -r switch to avoid escaping special characters and to move - in the range to the first or last position and to avoid its special value, it will look like this:

 sed -re "s/([a-zA-Z0-9./\\ :-]+)/\1/g" 

Otherwise, you will need either ( , ) and + , for example:

 sed -e "s/\([a-zA-Z0-9./\\ :-]\+\)/\1/g" 
+9
May 19 '13 at 17:31
source share



All Articles