zoukankan      html  css  js  c++  java
  • 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

    引申:

    在匹配行后添加,不需要像上面一样确定行号

    seq 5 |sed '3s/.*/& txt/'

  • 相关阅读:
    redis:高可用分析
    mysql:explain分析sql
    python中注意事项(更新)
    jupyter使用小技巧(更新)
    Jupyter中的快捷键
    Excel制作甘特图
    Vim编辑器常用命令
    Mysql主从
    常用MySql命令
    进程与线程的一个简单解释
  • 原文地址:https://www.cnblogs.com/rockstics/p/11364815.html
Copyright © 2011-2022 走看看