分页: 1 / 1

[已解决]"sed 's/abc/\1/'"提示"invalid reference \1",啥问题?

发表于 : 2016-10-15 2:11
科学之子
"sed 's/abc/\1/'"提示"invalid reference \1",啥问题?貌似并无网传的转义错误
网上搜都说是什么什么东西忘了转义了
但我这个这么简单的,貌似没什么忘记转义的吧?

Re: "sed 's/abc/\1/'"提示"invalid reference \1",啥问题?貌似并无网传的转义错

发表于 : 2016-10-15 2:19
科学之子

代码: 全选

$ sed --version
sed (GNU sed) 4.2.2
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo Bonzini.
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <[email protected]>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.

Re: "sed 's/abc/\1/'"提示"invalid reference \1",啥问题?貌似并无网传的转义错

发表于 : 2016-10-15 7:57
poloshiao
http://stackoverflow.com/a/4609965
\(...\) would capture the characters specified inside of the parens and \1 would be used to reference the first match, this is a part of regex.

Re: "sed 's/abc/\1/'"提示"invalid reference \1",啥问题?貌似并无网传的转义错

发表于 : 2016-10-15 9:31
vickycq

代码: 全选

$ echo 'aaaXXXaaa' | sed 's/XXX/\1/'
sed: -e expression #1, char 9: invalid reference \1 on `s' command's RHS
$ echo 'aaaXXXaaa' | sed 's/XXX/\\1/'
aaa\1aaa

Re: "sed 's/abc/\1/'"提示"invalid reference \1",啥问题?貌似并无网传的转义错

发表于 : 2016-10-15 11:50
astolia
就是\没有转义