我尝试在 sed print 命令中将
/
替换为 #
分隔符,但没有成功。请看下面第三行:
u@debian:~$ echo A | sed -n '/A/p'
A
u@debian:~$ echo A | sed -n '#A#p'
u@debian:~$ echo A | sed -n s#A#B#p
B
u@debian:~$
如何更换?
看看
info sed
,搜索* sed addresses
,然后搜索* Regexp Addresses
:
‘/REGEXP/’ This will select any line which matches the regular expression REGEXP. If REGEXP itself includes any ‘/’ characters, each must be escaped by a backslash (‘\’).
... ‘%REGEXP%’ (“%”可以替换为任何其他单个字符。)
This also matches the regular expression REGEXP, but allows one to
所以你必须转义你的第一个分隔符:
$ echo A | sed -ne '\#A#p'
A