12

I run this substitution command on Ubuntu 12.04.

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

However, the following error is raised.

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

I can remember the same expression works on MacOSX.
Can you describe why the command fails?

JJD
  • 50,076
  • 60
  • 203
  • 339

1 Answers1

19

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

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

Otherwise you will need to escape either (, ) and +, like:

sed -e "s/\([a-zA-Z0-9./\\ :-]\+\)/\1/g"
Birei
  • 35,723
  • 2
  • 77
  • 82
  • Thx! It works on the command line. Though, [here](http://stackoverflow.com/questions/16637799/sed-error-invalid-reference-1-on-s-commands-rhs) is a follow up question. – JJD May 19 '13 at 18:06