Artificial intelligent assistant

Matching substring within LDAP DN using Awk I'm looking to parse the output of an LDAP query. I want to retrieve a specific OU value within the DN that I am printing dn: ObjectName=Value,ou=12,ou=Users,dc=example,dc=com I am retrieving 3 total attributes values, but I only want the ou=[\d]{1,2} to be printed as part of the DN that I am printing. Here is an example of my code that gives the full DN: <LDAP SEARCH QUERY> | awk -F': ' '/dn: /{dn=$2}/^Attribute1: /{Attribute1=$2}/^Attribute2: /{print dn","Attribute1","$2}' I'm not sure how to parse the ou=12 in the example. I have tried several different but have not succeeded. I would like to use Awk to do this as this will be ported to several systems and perl/python isn't an option in all cases. I suppose it's like using grep -o but using Awk instead. Here is the desired output: 12,Attribute1,Attribute2

Here's what I ended up doing:


awk -F': ' '/^dn: /{split($2, ou, "," seps)}/^Attribute1/{Attribute1=$2}/^Attribute2/{print ou[2]","$2","Attribute1}'


The "ou=" is still there, but I am able to easily modify my script to accommodate.


ou=12,Attribute1,Attribute2

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 25c6afa193a9e6e01fc56681d9f663f9