You're replying to a comment by karn.

February 08, 2017, 16:11

Hello Peter, I am great fan of your awk lines.. i have below question if you could help in a better short way...

I am looking forward to Match all the three pattern from the command and place a space , it should be continue with all 3 matching pattern with the entire output received but in case if it gets only the first match it did not get rest two then don't print that single match at all ....

Below is the real command output from which i want to get this, where if you see first match "dn" searched and it don't contain othe 2 patterns of search. at the same time it would be great it we can have awk or sed itself in place of grep itself ...

$ ldapsearch -h myldapserver -x -LLL -b "ou=profile,o=ferry.com" "cn=*" | grep -Ei "^dn|defaultServerList|preferredServerList"
dn: cn=proxyagent,ou=profile,o=ferry.com
dn: cn=default,ou=profile,o=ferry.com
preferredServerList: 192.68.8.15 192.68.8.16
defaultServerList: 192.68.8.15 192.68.8.16 192.68.88.27
dn: cn=austin, ou=profile, o=ferry.com
defaultServerList: 192.68.63.10 10.209.208.23
preferredServerList: 192.68.88.14 10.28.15.10
dn: cn=sanjose, ou=profile, o=ferry.com
preferredServerList: 192.68.8.15 192.68.8.16
defaultServerList: 192.68.8.15 192.68.8.16 192.68.88.38

Expected output is :

dn: cn=proxyagent,ou=profile,o=ferry.com (--> This is single matched found without 2 others, which i don't want to be printed if its alone without 2 others)

dn: cn=default,ou=profile,o=ferry.com
preferredServerList: 192.68.8.15 192.68.8.16
defaultServerList: 192.68.8.15 192.68.8.16 192.68.88.27

dn: cn=austin, ou=profile, o=ferry.com
defaultServerList: 192.68.63.10 10.209.208.23
preferredServerList: 192.68.88.14 10.28.15.10

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "server_122": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.