我正试着评论这句话:
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
但它与我需要的不符,谁能告诉我我在这里做错了什么?
答案 0 :(得分:2)
如果您要做的只是评论passdb
和}
之间的界限,那么以下内容就足够了
sed -i '/^passdb {/,/}/s/^/#/g' file
答案 1 :(得分:1)
使用awk
awk '/^passdb {/,/^}/ {$0="#"$0}1' file