码迷,mamicode.com
首页 > 其他好文 > 详细

sed匹配多行进行替换

时间:2020-10-09 21:23:16      阅读:27      评论:0      收藏:0      [点我收藏+]

标签:com   服务器   def   文件   config   ret   memcach   服务   方式   

目前cache.php配置文件如下:

return [
    // 驱动方式
    ‘type‘   => ‘complex‘,

    ‘default‘ => [
        ‘type‘   => ‘memcache‘,
        // 服务器地址
        ‘host‘   =>‘192.168.1.2‘,
        // 端口
        ‘port‘   =>11211,
    ],
    // redis缓存
    ‘redis‘   =>  [
        // 驱动方式
        ‘type‘   => ‘redis‘,
        // 服务器地址
        ‘host‘  => ‘192.168.1.2‘,
        ‘expire‘ => 0,
        ‘port‘ => 6379,
        ‘timeout‘=> 3600,
    ],

];

下面我要把memcache的host地址改为memcache,redis的host地址改为redis

你肯定会想 sed -i ‘s#‘host‘ =>‘192.168.1.2‘,\n// 端口\n‘port‘ =>11211,#‘host‘ =>‘redis‘,\n// 端口\n‘port‘ =>11211,#g‘ cache.php
可是不会变

可以通过perl来进行替换
perl -0777 -i -pe "s/‘host‘ =>‘192.168.1.2‘,\n\/\/ 端口\n‘port‘ =>11211,/‘host‘ =>‘memche‘,\n\/\/ 端口\n‘port‘ =>11211,/ig" cache.config

sed匹配多行进行替换

标签:com   服务器   def   文件   config   ret   memcach   服务   方式   

原文地址:https://blog.51cto.com/fengwan/2540748

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!