Linux 使用条件取消注释范围内的行
如何取消注释从29行到39行的行,以及是否存在某个文本 文件内容master.cf:Linux 使用条件取消注释范围内的行,linux,bash,awk,sed,postfix-mta,Linux,Bash,Awk,Sed,Postfix Mta,如何取消注释从29行到39行的行,以及是否存在某个文本 文件内容master.cf: # # Postfix master process configuration file. For details on the format # of the file, see the master(5) manual page (command: "man 5 master" or # on-line: http://www.postfix.org/master.5.html). # # Do not
#
# Postfix master process configuration file. For details on the format
# of the file, see the master(5) manual page (command: "man 5 master" or
# on-line: http://www.postfix.org/master.5.html).
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (no) (never) (100)
# ==========================================================================
smtp inet n - y - - smtpd
#smtp inet n - y - 1 postscreen
#smtpd pass - - y - - smtpd
#dnsblog unix - - y - 0 dnsblog
#tlsproxy unix - - y - 0 tlsproxy
#submission inet n - y - - smtpd
# -o syslog_name=postfix/submission
# -o smtpd_tls_security_level=encrypt
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_tls_auth_only=yes
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=
# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#smtps inet n - y - - smtpd
# -o syslog_name=postfix/smtps
# -o smtpd_tls_wrappermode=yes
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=
# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#628 inet n - y - - qmqpd
pickup unix n - y 60 1 pickup
cleanup unix n - y - 0 cleanup
尝试了以下命令:
sed -e '29,/smtpd_client_restrictions/s/^#\ //' master.cf
但它将解锁从29到33的接下来5行
请指定如何执行此操作,smtpd_客户端_限制可以替换为其他文本
谢谢大家! 编辑:在看到OP的注释后,OP可能只需要取消注释第29到39行之间的匹配行,在这种情况下,请尝试:
awk 'FNR>=29 && FNR<=39{if($0~/smtpd_client_restrictions/){sub(/^#/,"")}} 1' Input_file
你能试试下面的吗。如果找到匹配的字符串,这将从第29到39行中删除注释
awk '
FNR>=29 && FNR<=39{
if($0~/smtpd_client_restrictions/){
found=1
}
dup_val=(dup_val?dup_val ORS:"")$0
sub(/^#/,"")
val=(val?val ORS:"")$0
if(FNR==39 && found){
print val
val=""
}
else{
print dup_val
dup_val=""
}
next
}
1
' Input_file
不,您的变体不适用,其中没有内容,如果您有,则需要拆分行。