简体   繁体   English

在Linux中使用sed取消注释和注释一行配置文件

[英]Uncomment and comment a line of config file using sed in linux

I am having the below text in my-config file 我的配置文件中包含以下文本

<!--<URL>www.abc.com</URL>-->
         www.xyz.com

I want to uncomment the commented line and comment the uncommented line. 我要取消注释注释行,并注释未注释行。 I tried using the sed command 我尝试使用sed命令

 sed -i '/<!--<URL>www.abc.com</URL>-->/s/^#//g' filename

but getting error as 但由于错误

sed: -e expression #1, char 24: unknown command: /'` sed: -e expression #1, char 24: unknown command: /'`

please help in resolving this or correct if anything wrong in my sed command. 请帮助解决此问题,或者在我的sed命令中纠正任何错误。 Thanks in advance. 提前致谢。

Since you're using the '/' as the sed delimiter, you must escape '\\' the '/' in the tag. 由于您将'/'用作sed分隔符,因此必须在标记中转义'\\''/'。

eg 例如

 sed -i '/<!--<URL>www.abc.com<\/URL>-->/s/^#//g' filename

You can also switch your delimiter in sed for better readability more . 您也可以将您的分隔符在SED可读性更好更多

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

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