Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve lines in variable rows 1

Status
Not open for further replies.

kHz

MIS
Dec 6, 2004
1,359
US
I have a file with a number of records from an LDAP search and need to retrieve two lines. But the two lines are not always on the same row and one line does not always exits.

Example:
uid=techie,ou=people,dc=example,dc=com
objectClass=posixAccount
objectClass=shadowAccount
objectClass=account
objectClass=top
uid=techie
cn=techie
uidNumber=14
gidNumber=27
gecos=userx
homeDirectory=/export/home/userx
loginShell=/usr/bin/ksh

uid=ipsec,ou=people,dc=example,dc=com
objectClass=posixAccount
objectClass=shadowAccount
objectClass=account
objectClass=top
uid=ipsec
cn=ipsec
uidNumber=16
gidNumber=1
homeDirectory=/etc/ipsec
loginShell=/usr/bin/ksh

uid=guest,ou=people,dc=example,dc=com
uidNumber=55
objectClass=posixAccount
objectClass=shadowAccount
objectClass=account
objectClass=top
uid=guest
cn=guest
gidNumber=23
gecos=Guest User
homeDirectory=/export/home/guest
loginShell=/usr/bin/ksh

Notice how the records are different. What I want to return is the cn and gecos from each record.

So it would return:
cn=techie
gecos=userx

cn=ipsec

cn=guest
gecos=Guest User

Thanks!!
 
Something like this ?
awk '/^cn=/||/^gecos=/||!NF' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top