Basically I want to write a script that could automatically copy a Drupal 7 settings.php file and search/replace the database name with a different one.
Before starting with sed or something like that I've just been trying to grep out the database name, just to get the regular expression down.
So far I've had no luck, my best guess has been grep "'database' =>" settings.php
That gives me the output:
* 'database' => 'databasename', * 'database' => 'databasename', * 'database' => 'databasename', * 'database' => 'databasename', * 'database' => '/path/to/databasefilename', 'database' => 'MY_DATABASE',
I just want the last line 'database' => 'MY_DATABASE', but really just the name so ideally the output would just be MY_DATABASE.
Any thoughts?
After some playing around I came up with this:
grep "'database' =>" settings.php | grep -v '^\ \*'
it gives me the output:
'database' => 'MY_DATABASE',
Not so elegant but it gave me some output I can work with.