没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
sed删除指定行的上一行
有这么一个需求,需要从若干个apache虚机配置文件中删除一段内容,类似下面这种
<VirtualHost *>
ServerName abc.com
DocumentRoot /home/apache/abc
CustomLog logs/abc.com-access_log combined
</VirtualHost>
思路:以ServerName为中心,删除上面的一行,再删除从ServerName到</VirtualHost>之间的内容即可。
脚本如下:
#! /bin/sh
# by logo32.iteye.com
# delete domain from *.conf
Dir="/usr/local/apache2/conf"
cd $Dir
ls *.conf | while read file
do
con=`grep 'ServerName abc.com' $file | wc -l`
if [ $con -gt 0 ];then
echo "delete domain in this file : $Dir/$file"
sed -i -e :a -e '$!N;s/.*\n\(.*ServerName abc.com\)/\1/;ta' -e 'P;D' $file
sed -i '/ServerName abc.com/,/\/VirtualHost/d' $file
else
echo "======== no change for file : "$file
fi
done
有这么一个需求,需要从若干个apache虚机配置文件中删除一段内容,类似下面这种
<VirtualHost *>
ServerName abc.com
DocumentRoot /home/apache/abc
CustomLog logs/abc.com-access_log combined
</VirtualHost>
思路:以ServerName为中心,删除上面的一行,再删除从ServerName到</VirtualHost>之间的内容即可。
脚本如下:
#! /bin/sh
# by logo32.iteye.com
# delete domain from *.conf
Dir="/usr/local/apache2/conf"
cd $Dir
ls *.conf | while read file
do
con=`grep 'ServerName abc.com' $file | wc -l`
if [ $con -gt 0 ];then
echo "delete domain in this file : $Dir/$file"
sed -i -e :a -e '$!N;s/.*\n\(.*ServerName abc.com\)/\1/;ta' -e 'P;D' $file
sed -i '/ServerName abc.com/,/\/VirtualHost/d' $file
else
echo "======== no change for file : "$file
fi
done
资源评论
qq_20079841
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功