Fri 15 Feb 2008
I get several requests for directory data in CSV format. Until openldap has a csv output option, we will use SED to save the day!
ldapsearch -h localhost -b o=mydomain,c=us uid=sbak* mail telephonenumber
dn: GID=0000001,o=mydomain,c=us
telephoneNumber: 1-734-555-0001
mail: sbak@mydomain.com
dn: GID=0000002,o=mydomain,c=us
telephoneNumber: 1-734-555-0002
mail: sbaker@mydomain.com
If we redirected the above date to a file 11.txt we can than run this command to place a comma at the end of every line:
sed -n '1h;2,$H;${g;s/\n/,/g;p}' 11.txt > 22.txt
Next we will use a simple sed to replace the double comma with a newline:
sed 's/,,/\n/g' 22.txt > 33.csv
Lets look at 33.csv to see the finished product:
sbak@fedoraCore:~ $ cat 33.csv
dn: GID=0000001,o=mydomain,c=us,telephoneNumber: 1-734-555-0001,mail: sbak@mydomain.com
dn: GID=0000002,o=mydomain,c=us,telephoneNumber: 1-734-555-0002,mail: sbaker@mydomain.com
Now you can send your managers data that they can open with excel!