zoukankan      html  css  js  c++  java
  • linux批量替换文件内容

    需求:需要批量替换IP,以下3.26全部需要成3.27。

    [qipai@beta-27 hall0]$ grep -wR  '10.0.3.26' ./*
    ./action.log:12-19 18:37:44 | Http Game        : http://10.0.3.26 
    ./action.log:12-19 18:37:44 | Http Download    : http://10.0.3.26 
    ./action.log:12-19 18:37:44 | Http SDK         : http://10.0.3.26 
    ./action.log:12-19 18:37:44 | Servers 00/01 : 02 :       10.0.3.26 :       127.0.0.1 :       127.0.0.1 : srv1 
    ./script/configure.json:                "http_game":"http://10.0.3.26:8040"
    ./script/configure.json:        "http://10.0.3.26:8089"
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head01_1.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head01_2.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head01_3.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head01_4.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head01_5.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head01_6.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head02_1.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head02_2.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head02_3.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head02_4.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head02_5.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head02_6.png"
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head01_1.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head01_2.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head01_3.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head01_4.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head01_5.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head01_6.png"
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head02_1.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head02_2.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head02_3.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head02_4.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head02_5.png",
    ./script/configure.json:            "http://10.0.3.26:8089/headpics/head02_6.png"
    ./script/configure.json:        "http://10.0.3.26:8089/headpics/head_verifying.png"
    ./script/control.json:        "http.download":"http://10.0.3.26",
    ./script/control.json:        "http.game":"http://10.0.3.26",
    ./script/control.json:        "http.sdk":"http://10.0.3.26",
    ./script/control.json:                "internet":"10.0.3.26",
    ./script/control.json:                "internet":"10.0.3.26",
    ./script/control.json:                "internet":"10.0.3.26",
    ./source/tygame-sdk/configure/game/game_clientid.py:        'http_game': "http://10.0.3.26:8040",
    ./source/tygame-sdk/configure/game/global_avatar.py:photoDownloadHttpDomain = 'http://10.0.3.26:8089'
    ./source/tygame-sdk/configure/server/online.json:    "http.sdk" : "http://10.0.3.26",
    ./source/tygame-sdk/configure/server/online.json:        "internet" : "10.0.3.26",

    sed  结合 grep 实现

    [qipai@beta-27 hall0]$ sed 's#10.0.3.26#10.0.3.27#g' -i  `grep -wRl '10.0.3.26' ./*`

    grep参数说明:

    -w   精确匹配

    -R  递归查找

    -l   获取文件路径

    查看结果:

    [qipai@beta-27 hall0]$ grep -wR '10.0.3.27' ./*
    ./action.log:12-19 18:37:44 | Http Game        : http://10.0.3.27 
    ./action.log:12-19 18:37:44 | Http Download    : http://10.0.3.27 
    ./action.log:12-19 18:37:44 | Http SDK         : http://10.0.3.27 
    ./action.log:12-19 18:37:44 | Servers 00/01 : 02 :       10.0.3.27 :       127.0.0.1 :       127.0.0.1 : srv1 
    ./script/configure.json:                "http_game":"http://10.0.3.27:8040"
    ./script/configure.json:        "http://10.0.3.27:8089"
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head01_1.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head01_2.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head01_3.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head01_4.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head01_5.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head01_6.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head02_1.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head02_2.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head02_3.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head02_4.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head02_5.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head02_6.png"
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head01_1.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head01_2.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head01_3.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head01_4.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head01_5.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head01_6.png"
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head02_1.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head02_2.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head02_3.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head02_4.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head02_5.png",
    ./script/configure.json:            "http://10.0.3.27:8089/headpics/head02_6.png"
    ./script/configure.json:        "http://10.0.3.27:8089/headpics/head_verifying.png"
    ./script/control.json:        "http.download":"http://10.0.3.27",
    ./script/control.json:        "http.game":"http://10.0.3.27",
    ./script/control.json:        "http.sdk":"http://10.0.3.27",
    ./script/control.json:                "internet":"10.0.3.27",
    ./script/control.json:                "internet":"10.0.3.27",
    ./script/control.json:                "internet":"10.0.3.27",
    ./source/tygame-sdk/configure/game/game_clientid.py:        'http_game': "http://10.0.3.27:8040",
    匹配到二进制文件 ./source/tygame-sdk/configure/game/game_clientid.pyc
    ./source/tygame-sdk/configure/game/global_avatar.py:photoDownloadHttpDomain = 'http://10.0.3.27:8089'
    匹配到二进制文件 ./source/tygame-sdk/configure/game/global_avatar.pyc
    ./source/tygame-sdk/configure/server/online.json:    "http.sdk" : "http://10.0.3.27",
    ./source/tygame-sdk/configure/server/online.json:        "internet" : "10.0.3.27",
  • 相关阅读:
    《GDB常用基本》
    《Linux守护进程》
    <C语言知识点 —— 数组赋值字符串>
    《Linux知识点》
    玩转----select模块操作下拉框-selenium
    玩转----selenium--下拉框select
    玩转----selenium-滚动条的几种方式
    玩转----python-装饰器
    玩转----解决selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid 'expiry'
    玩转----iframe框架怎样来定位,并说明iframe框架中不变和可变的属性分别是什么?多个iframe框架怎么处理?iframe和frame区别:
  • 原文地址:https://www.cnblogs.com/root0/p/10149175.html
Copyright © 2011-2022 走看看