I ended up using nsswitch.conf file grammar for this.
Obviously not perfect, but does the job.
There are some caveats such as white spaces in the values that you have to be aware of.
If nsswitch.conf grammar gets you close, perhaps use that as a template and modify as necessary to suit your needs?
Thank you it solved my purpose.