Suppressing empty output lines when using ldapsearch

Problem

You want to use ldapsearch to search from a file (file contains domains and ldap contains emails), but you want to suppress empty output lines (option -LLL does not seem to suppress them).

Solution

Use grep -v ‘^$’ like

ldapsearch -LLL -H "ldaps://ldap_url:nnnn" -D "cn=Directory Manager" -w $LDP -b "ou=ou_name,dc=domain,dc=com" -s sub -f denyDomains.txt  "(mail=*@%s)" uid mail status | grep -v '^$' > denyDomainsResults.txt