sed 批量修改文件

#!/bin/bash
Judge()
{
if [ $? -ne 0 ];then
echo ${i} >>error.log
fi

}

sed -i "/CLOUDWISE_REQUEST_INFO/s/^/#/" nginx.default.conf   ##注释含有CLOUDWISE_REQUEST_INFO 的行

sed -i 's/warn//' ssl_host/nginx.default.conf    ##删除某一行中字符串warn

 

##修改匹配到的某字符串所在行的下一行
num=`grep -n "static" nginx.default.conf | awk -F ':' '{print $1}'`
sed -i "$((${num}+1))c\ proxy_pass http://localhost;"  nginx.default.conf

##根据匹配到的某一行,在其上N行插入需要的location模块
num=$(cat vhost/nginx.default.conf |grep -n -w "static" | awk -F : '{print $1}')
sed -i "${num}i\ location ~* ^/system-manager/ {" nginx.default.conf
sed -i "$((${num}+1))i\ proxy_pass http://localhost;" nginx.default.conf
sed -i "$((${num}+2))i\ proxy_set_header Host \"  www.myself.com\";" nginx.default.conf
sed -i "$((${num}+3))i\ }" nginx.default.conf
sed -i "$((${num}+4))i\ " nginx.default.conf

 

Judge

done

转载于:https://www.cnblogs.com/rockstics/p/11364815.html

你可能感兴趣的:(运维,awk)