当前位置: 技术问答>linux和unix
sh脚本的正则表达式问题?
来源: 互联网 发布时间:2016-12-14
本文导语: 比如现在有包含如下内容的/root/test.conf文件: ------------------------------------------------------- managesieve { # To fool ManageSieve clients that are focused on timesieved you can # specify the IMPLEMENTATION capability that the dovecot ...
比如现在有包含如下内容的/root/test.conf文件:
-------------------------------------------------------
managesieve {
# To fool ManageSieve clients that are focused on timesieved you can
# specify the IMPLEMENTATION capability that the dovecot reports to clients
# (default: "dovecot").
}
# To fool ManageSieve clients that are focused on timesieved you can
# specify the IMPLEMENTATION capability that the dovecot reports to clients
# (default: "dovecot").
protocol managesieve {
# To fool ManageSieve clients that are focused on timesieved you can
# specify the IMPLEMENTATION capability that the dovecot reports to clients
# (default: "dovecot").
}
# To fool ManageSieve clients that are focused on timesieved you can
# specify the IMPLEMENTATION capability that the dovecot reports to clients
# (default: "dovecot").
-----------------------------------------------------------------
想要通过脚本删除
protocol managesieve {
# To fool ManageSieve clients that are focused on timesieved you can
# specify the IMPLEMENTATION capability that the dovecot reports to clients
# (default: "dovecot").
}
系统是CentOS 5.6, 我现在这么写:
sed -i 's/protocol managesieve[ ]*{[^}]*}/#protocol managesieve deleted/' /root/test.conf
但测试结果文件毫无改变,请问应该怎样修改?谢谢。
-------------------------------------------------------
managesieve {
# To fool ManageSieve clients that are focused on timesieved you can
# specify the IMPLEMENTATION capability that the dovecot reports to clients
# (default: "dovecot").
}
# To fool ManageSieve clients that are focused on timesieved you can
# specify the IMPLEMENTATION capability that the dovecot reports to clients
# (default: "dovecot").
protocol managesieve {
# To fool ManageSieve clients that are focused on timesieved you can
# specify the IMPLEMENTATION capability that the dovecot reports to clients
# (default: "dovecot").
}
# To fool ManageSieve clients that are focused on timesieved you can
# specify the IMPLEMENTATION capability that the dovecot reports to clients
# (default: "dovecot").
-----------------------------------------------------------------
想要通过脚本删除
protocol managesieve {
# To fool ManageSieve clients that are focused on timesieved you can
# specify the IMPLEMENTATION capability that the dovecot reports to clients
# (default: "dovecot").
}
系统是CentOS 5.6, 我现在这么写:
sed -i 's/protocol managesieve[ ]*{[^}]*}/#protocol managesieve deleted/' /root/test.conf
但测试结果文件毫无改变,请问应该怎样修改?谢谢。
|
sed -i '/protocol managesieve[ ]*{/,/^}$/d' yourfile