Greetings Stack Overflow community.
I'm currently struggling with a relatively simple thing. To automatically find and log Application configurations, I am currently working on a script that reads out configuration data from the config file of certain applications. Since these config files can vary in syntax, and the only constant is the pattern of for example db names, I want to extract these db names though a regex.
For Example:
The DB names always have the syntax db_s{serverid}_{dbid}
where the serverid consists of 2-4 numbers, and the database id of 2-4 numbers, counting up. valid DB names would be for example:
db_s0001_01
db_s1337_42
db_s123_123
db_s42_1337
Database Names are stored in config files with varying syntax, depending on the used Application. Here are some examples:
define( 'DB_NAME', 'db_s0001_01' );
define( 'DB_NAME', "db_s0001_01" );
'dbname' => 'db_s0001_01',
'dbname' => "db_s0001_01",
database_name: db_s0001_01
Breaking down the config files to get the right lines for the right credential variables is not the problem. But how would I go on and extract the precise database-name out of the config-strings?
The Regex should be something like
(db_s[0-9]{2,4}_[0-9]{2,4})
But I can't quite get behind which tool to use and how to extract the exact Database name. So how would get only the DB name out of this?
echo 'define( 'DB_NAME', "db_s0001_01" );' | grep/sed/awk (db_s[0-9]{2,4}_[0-9]{2,4})
echowithout any pipe, it doesn't print what you expect.