Tuesday, November 17, 2009

awk: parse a conf file having "a=b" entries

Given a config file (i.e. a text input file to a test) containing "A=B" key/value pairs like the one below:

[root@mttf ~]# head authPerf.conf
domain = mttf.appfwk.net
testidentity = appfwk1
identityNameTemplate = test
password = abcabc
adminpassword = abcdef123

PROBLEM: How can I get the RHS of each "="? In other words, how can I get the values of 'domain', 'testidentity', 'password' etc?

SOLUTION: use AWK!
[root@mttf ~]# grep "domain" authPerf.conf | awk  -F= '{gsub(/^[ \t]+/ , "", $2); print $2}'
mttf.appfwk.net

No comments: