使用sed在文件中的指定字符串后插入文件内容

时间:2017-02-27 23:14:48

标签: bash sed

我有以下文件:

蒙戈

    'mongodb' => [
        'driver'   => 'mongodb',
        'host'     => env('DB_HOST', 'localhost'),
        'port'     => env('DB_PORT', 27017),
        'database' => env('DB_DATABASE'),
        'username' => env('DB_USERNAME'),
        'password' => env('DB_PASSWORD'),
        'options'  => [
            'database' => 'admin' // sets the authentication database required by mongo 3
        ]
    ],

和sed命令:

sed -i "/'connections' => \[/a \ "$(cat mongo)" \\" /app/config/database.php

所以我想在字符串后面插入mongo文件的内容:

'connections' => [

搜索很好,sed找到了字符串,但没有正确获取文件mongo的内容。

我收到以下错误:

sed: can't read 'mongodb': No such file or directory
sed: can't read =>: No such file or directory
sed: can't read [: No such file or directory
sed: can't read 'driver': No such file or directory
sed: can't read =>: No such file or directory
sed: can't read 'mongodb',: No such file or directory
sed: can't read 'host': No such file or directory

1 个答案:

答案 0 :(得分:1)

这可能适合你(GNU sed):

 sed -i '/'\''connections'\'' => \[/r mongoFile' file

connections地址后阅读mongoFile。