Filter ldapsearch with awk/bash
<p>By writing an <code>ldapsearch</code> command such as:</p>

<pre><code>ldapsearch -h ipaddress -p 389 -D "cn=func_01_acc,ou=admins,dc=akademia,dc=int" \
-w akademia.01 -b "ou=stud01,dc=akademia,dc=int" "(l=Torun)" sn cn telephonenumber -LLL |
grep sn: | awk '{print $2 "|" $1}' | sort | uniq -u 
</code></pre>

<p>I got output:</p>

<pre><code> dn: uid=s21705,ou=stud01,dc=akademia,dc=int
 telephoneNumber: +78123793414
 cn: Benny Flowers

 dn: uid=s21711,ou=stud01,dc=akademia,dc=int
 telephoneNumber: +78123439058
 cn: Jacqueline Newton
</code></pre>

<p>The question is: how to format it to</p>

<pre><code>Benny Flowers|+78123793414
JAcqueline Newton|+78123439058
</code></pre>

<p>The farest I went was:</p>

<pre><code>ldapsearch -h ipaddress -p 389 -D "cn=func_01_acc,ou=admins,dc=akademia,dc=int" \
-w akademia.01 -b "ou=stud01,dc=akademia,dc=int" "(l=Torun)" sn cn telephonenumber -LLL |
grep sn: | grep  dn: | sed 's/telephoneNumber: //' | sed 's/cm: //'
</code></pre>

<p>And I have:</p>

<pre><code> +123123123
 Name Surname

 +123123123
 Name Surname
</code></pre>

<p>I tried to invert number and names with:</p>

<pre><code> for ((i=0;i&lt;$elements;i++)); do
      echo ${array[${i}]}
 done
</code></pre>

<p>It printed output, but I cannot find out how to pass value to temporary array for names and for another array handling numbers.</p>

<p>Any suggestions would be helpful.</p>