本文介绍了sed 错误“无效范围结束";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Ubuntu 12.04 上运行这个替换命令.
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 表达式 #1, char 27: 无效范围结束
我记得在 MacOSX 上有相同的表达式.
你能描述命令失败的原因吗?
I can remember the same expression works on MacOSX.
Can you describe why the command fails?
推荐答案
您可以通过两种方式解决.其中之一是使用 -r
开关来避免转义特殊字符并将范围内的 -
移动到第一个或最后一个位置并避免其特殊含义,它会像:
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"
这篇关于sed 错误“无效范围结束";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!