Need help on awk/sed/ perl pattern with regex / grep
Posted
by
Jayakumar K
on Server Fault
See other posts from Server Fault
or by Jayakumar K
Published on 2011-02-09T11:31:49Z
Indexed on
2011/02/09
15:27 UTC
Read the original article
Hit count: 396
Sample file output from grep
file1:my $dbh = DBI->connect("dbi:mysql:$database_name", $DB_USER, $DB_PASSWD)
file2:($dbc,$rc) = mysql_connect($mysql_host,$mysql_user,$mysql_password);
The awk pattern should get values databasename, DB_USER And DB_PASSWD from line 1
and mysql_host,mysql_user and mysql_password from line 2
i.e all variables inside the function.
Then it should search for the declaration of that variable in file before : (semicolon)
ex: databasename in file1 may be
$databasename = "dbweb" ;
ex: mysql_user in file2 may be
$mysql_user="root" ;
Result: It should display variable declarations of all 6 variables along with filenames
file2:$mysql_host = "db1";
file2:$mysql_user = "root";
file1:$DB_USER = 'user';
© Server Fault or respective owner