0

我试图评论这一行:

passdb {
  driver = pam
   [session=yes] [setcred=yes] [failure_show_msg=yes] [max_requests=<n>]
   [cache_key=<key>] [<service name>]
  args = dovecot
}

通过 sed:

sed -i '1!N; s/passdb {\
  driver = pam\
   \[session=yes\] \[setcred=yes\] \[failure_show_msg=yes\] \[max_requests=\<n\>\]\
   \[cache_key=\<key\>\] \[\<service name\>\]\
  args = dovecot\
}/#passdb {\
#  driver = pam\
#   [session=yes] [setcred=yes] [failure_show_msg=yes] [max_requests=<n>]\
#   [cache_key=<key>] [<service name>]\
#  args = dovecot\
#}/' t

但它不符合我的需要,谁能告诉我我在这里做错了什么?

4

2 回答 2

2

如果您要做的只是注释 and 之间的行passdb}那么以下内容就足够了

sed -i '/^passdb {/,/}/s/^/#/g' file
于 2013-09-24T00:34:14.153 回答
1

使用awk

awk '/^passdb {/,/^}/ {$0="#"$0}1' file
于 2013-09-24T06:42:03.863 回答