Sunday, June 5, 2022

[SOLVED] Grep db_name from codeigniter configuration

Issue

I created a script to backup database and system in separate directory, the directory will contain the system and its database. So I need to know what database the system had/use.

My whole project is using codeigniter framework, I see that database information is defined on database.php, so what Im trying to do is pulling database name into my bash script.

So far, I can only do this.

$ grep -F "['default']['database']" config/database.php 
$db['default']['database'] = 'mydatabase';

I need to extract mydatabase and left out other parts, how would I do that with grep/sed/awk ?


Solution

Try this:

$ grep -F "['default']['database']" config/database.php | cut -d = -f 2- | cut -d \' -f 2
mydatabase


Answered By - Arnaud Valmary
Answer Checked By - Marie Seifert (WPSolving Admin)