简体   繁体   English

Bash sed如何遮罩括号

[英]Bash sed how to mask brackets

I want to search for 'start') in the file /etc/init.d/fhem , and write code which I read from a textfile to that file after the statement above. 我想在文件/etc/init.d/fhem搜索'start') ,并在上面的语句之后将我从文本文件读取的代码写入该文件。 At the moment I get a message that I have to close the bracket from 'start') . 目前,我收到一条消息,必须从'start')关闭括号。 I think I have to mask it properly, but so far no luck with trying that. 我认为我必须适当地掩盖它,但是到目前为止,尝试这样做还没有运气。 May someone give me the missing link? 有人可以给我丢失的链接吗?

CocConf=$(<COC.txt)#Reading Cod from File to insert in other file
sed -r "\'start\')/a $CocConf" /etc/init.d/fhem #Inserting said Code

You're missing the / before the regular expression. 您在正则表达式前缺少/ And there's no need to escape single quotes inside double quotes. 并且无需在双引号内转义单引号。 But when you use extended regexps, you need to escape parentheses. 但是,当您使用扩展的正则表达式时,需要转义括号。 The a command also requires a backslash after it, and the text to be added must be on the next line. a命令后还需要反斜杠,并且要添加的文本必须在下一行。

sed -r "/start\)/a\
$CocConf" /etc/init.d/fhem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM