2017-02-27 83 views
0

我有以下文件:插入文件內容的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 
+0

這看起來像來自php的'var_dump()'輸出。對? – hek2mgl

+0

像......這樣的數組是一個我想要插入到配置php文件中的配置。 –

回答

1

這可能爲你工作(GNU SED):

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

閱讀mongoFile在connections地址之後。