sed error: “invalid reference \\1 on `s' command's RHS”

做~自己de王妃 提交于 2019-11-28 07:07:09
Denis de Bernardy

Don't you need to actually capture for that to work? i.e. for variant 2:

-r -e "s/WARNING: (\([a-zA-Z0-9./\\ :-]\+\))/${warn}WARNING: \1${c_end}/g" \

(Note: untested)

Without the -r argument back-references (like \1) won't work.

e18r

This error is common for parentheses that are not escaped. Escape them and try again.


For example:

/^$/b
:loop
$!{
N
/\n$/!b loop
}
s/\n(.)/\1/g

Should be escaped with backslashes before each parenthesis:

/^$/b
:loop
$!{
N
/\n$/!b loop
}
s/\n\(.\)/\1/g
slackmart

You need escape the / after the .

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

Or if you don't want to worry about escaping, use |

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

EDIT:

sed -e "s|WARNING: \([a-zA-Z0-9.-/\\ :]+\)|${warn}WARNING: \1${c_end}|g"

If the -r/--regexp-extended option is not provided, then the capturing parentheses must be escaped.

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