Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Awk command/script to parse/extract file

Charles MOct 20 2016 — edited Oct 21 2016

Hi all.

I am trying to create a script, or command(s) that will parse/extract some data from a text file. In this case, it is an ldap export from WebLogic. Below is an example of the entries in the file (some characters have been changed to mask the actual values). There are around a thousand of these entries, all the same format. This is the first two.

dn: uid=1111,ou=people,ou=@realm@,dc=@domain@
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
objectclass: wlsUser
cn: 1111
sn: 1111
uid: 1111
userpassword:: not real

createTimestamp: 201508210200Z
creatorsName: cn=Admin
wlsMemberOf: cn=PayablesProcessor,ou=groups,ou=@realm@,dc=@domain@
wlsMemberOf: cn=InvoiceViewer,ou=groups,ou=@realm@,dc=@domain@
wlsMemberOf: cn=PayablesSpecialist,ou=groups,ou=@realm@,dc=@domain@
wlsMemberOf: cn=SupplierMaintenance,ou=groups,ou=@realm@,dc=@domain@
wlsMemberOf: cn=MailRoom,ou=groups,ou=@realm@,dc=@domain@
wlsMemberOf: cn=Administrators,ou=groups,ou=@realm@,dc=@domain@
modifyTimeStamp: 201600292340Z
modifiersName: cn=Admin

dn: uid=2222,ou=people,ou=@realm@,dc=@domain@
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
objectclass: wlsUser
cn: 2222
sn: 2222
uid: 2222
userpassword:: not real
wlsMemberOf: cn=InvoiceViewer,ou=groups,ou=@realm@,dc=@domain@
modifyTimeStamp: 201507121255Z
modifiersName: cn=Admin
createTimestamp: 201508210200Z
creatorsName: cn=Admin

What I am trying to do is get the 'sn:' value and the 'wlsMemberOf:' ... in that order. I've come up with a few commands that pull these values. But, I need some logic to get all of the neccesary values, formatted the way I need it.

strings <file_name>.dat | grep sn | gawk '{print $2}' | sort (would give):

1111

2222

strings <file_name>.dat | grep wlsMemberOf | gawk '{print $2}' | cut -d, -f1 | cut -d= -f2 (would give):

PayablesProcessor

InvoiceViewer

PayablesSpecialist

SupplierMaintenance

MailRoom

Administrators

InvoiceViewer

What I need would look something like this:

1111     PayablesProcessor

1111     InvoiceViewer

1111     PayablesSpecialist

1111     SupplierMaintenance

1111     MailRoom

1111     Administrators

2222     InvoiceViewer

Any help is appreciated.

Thanks,

Charles

This post has been answered by Tommy.Reynolds-Oracle on Oct 20 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2016
Added on Oct 20 2016
9 comments
1,763 views