sed删除指定行的上一行
有这么一个需求,需要从若干个apache虚机配置文件中删除一段内容,类似下面这种
<VirtualHost *> ServerName abc.com DocumentRoot /home/apache/abc CustomLog logs/abc.com-access_log combined</VirtualHost>
#! /bin/sh# by logo32.iteye.com# delete domain from *.confDir="/usr/local/apache2/conf"cd $Dirls *.conf | while read filedocon=`grep 'ServerName abc.com' $file | wc -l`if [ $con -gt 0 ];thenecho "delete domain in this file : $Dir/$file"sed -i -e :a -e '$!N;s/.*\n\(.*ServerName abc.com\)/\1/;ta' -e 'P;D' $filesed -i '/ServerName abc.com/,/\/VirtualHost/d' $fileelseecho "======== no change for file : "$filefidone