sed匹配多行进行替换

目前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

猜你喜欢

转载自blog.51cto.com/fengwan/2540748