sed error “Invalid range end”

依然范特西╮ 提交于 2019-12-17 19:49:54

问题


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?


回答1:


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"


来源:https://stackoverflow.com/questions/16637432/sed-error-invalid-range-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!