I would like to extract database access information from a wordpress wp-config.php file.
Example (double quotes):
define( "DB_NAME", "mydatabase" );
But it might as well look like this (single quotes)
define( 'DB_NAME', 'mydatabase' );
A mixed version is also possible:
define( 'DB_NAME', "mydatabase" );
So far I have found this on the internet:
DBNAME=`cat wp-config.php | grep DB_NAME | cut -d ' -f 4`
This works when single quotes are used. What I am looking for is a regex that would handle all cases.
Thank you
2
Answers
Input file
or
With php:
With
GNU grep
:Output
How about
awk
?Your example File:
The Command:
The Output:
mydatabase.com