替换命令后的 SED 字符(“s") [英] SED character after the substitute command ("s")
问题描述
我知道sed
中的s//
类型命令,但从未见过使用s#
.有人可以解释一下这到底是在做什么吗?
I know about s//
type command in sed
, however never saw using s#
. Could someone explain what exactly this is doing?
% sed -e "s#SRC_DIR=.*#SRC_DIR=$PROJECT_SRC_DIR#g" -i proj.cfg
我知道 -e
定义了一个要执行的脚本,并且该脚本与 ""
一起使用,但是 s#
究竟是做什么的?
I understand that -e
defines a script to execute, and the script is withing ""
, but what exactly s#
does?
已检查 http://www.grymoire.com/Unix/Sed.html和 gnu 网站,但没有运气.
Checked http://www.grymoire.com/Unix/Sed.html and gnu website, but no luck.
推荐答案
#
是一个类似于 /
的 sed 分隔符.我们可以使用 ~
、#
、/
、;
等作为 sed 分隔符.他们使用不同的分隔符 #
因为他们不想转义 /
斜杠.如果使用 #
作为分隔符,则不需要转义 /
正斜杠.但是如果您使用 /
作为分隔符,则必须将 /
转义为 \/
否则 sed 会考虑 /
> 作为分隔符.
#
is a sed delimiter like /
. We could use ~
, #
, /
, ;
, etc as sed delimiters. They uses a different delimiter #
because they don't want to escape /
slashes. If you use #
as delimiter, you don't need to escape /
forward slash. But if you use /
as delimiter, you must need to escape /
as \/
or otherwise sed would consider /
as delimiter.
这篇关于替换命令后的 SED 字符(“s")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!