Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I think I'm looking at awk vs PHP vs Perl vs cut. Maybe.

I want to look at wp-config.php and look at these lines:

define('DB_NAME', 'mydb');
define('DB_USER', 'myuser');
define('DB_PASSWORD', 'xx');

And pull out the strings "mydb" and "myuser" and the password, so I can do something with it, e.g.:


..insert magical code here to store strings into DBNAME, USERNAME, PASSWORD...
mysqldump -u $USERNAME -p$PASSWORD $DBNAME > /tmp/blah.sql

Any suggestions?

share|improve this question
You could write your script in PHP and simply include the config file. – Zoredache May 23 '13 at 8:07

Here is quick and dirty awk hack:

awk -F "'" '{print $4}' wp-config.php

You can also try cut:

cut -d"'" -f 4 wp-config.php

EDIT: to set variables this should work:

USERNAME=`grep DB_NAME wp-config.php | awk -F "'" '{print $4}'`

And so on..

share|improve this answer
Ok, the awk line works. But how do I get the results into those variables? – CaptSaltyJack May 23 '13 at 16:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.