title: grep, cut and remove \n from file
body: <p>I'm working with an input file containing a list of user ID's on a new line. Within a bash script I run a while loop on that input file doing an ldapsearch query using grep -E to filter for my desired results. The generated output file is currently formatted as follows (/mountpoint/out_file_1.out);</p>
  <pre><code>uid=user_id1,cn=Users,ou=Department,dc=myORG    
  LDAPresource=myORG_RESname1   LDAPresource=myORG_RESname2  
  uid=user_id2,cn=Users,ou=Department,dc=myORG  
  LDAPresource=myORG_RESname2   LDAPresource=myORG_RESname3
  </code></pre>
  <p>The desired output, however, should look as follows;</p>
  <p>user_id1;myORG_RESname1<br />
  user_id1;myORG_RESname2<br />
  user_id2;myORG_RESname2<br />
  user_id2;myORG_RESname3</p>
  <p>So far, I've tried using grep and cut to achieve the above desired output. Here the exact commands I'm running on that first results file above:</p>
  <pre><code>grep -E '(^uid=|myORG_RESname1|myORG_RESname2|myORG_RESname3)' /mountpoint/out_file_1.out | cut -d, -f1 &gt;&amp;5
  </code></pre>
  <p>which results in a second output (/mountpoint/out_file_2.out);</p>
  <pre><code>uid=user_id1  
  LDAPresource=myORG_RESname1     
  LDAPresource=myORG_RESname2  
  </code></pre>
  <p>again, running another grep with cut:</p>
  <pre><code>grep -E 'LDAPresource|uid=' /mountpoint/out_file_2.out | cut -d= -f2 &gt;&amp;6
  </code></pre>
  <p>finally produces this output (/mountpoint/out_file_3.out):</p>
  <pre><code>user_id1  
  myORG_RESname1  
  myORG_RESname2  
  </code></pre>
  <p>which is &quot;almost&quot; what I need. The last output I've generated, needs to get rid of the newline and repeat the user ID for every Resource Name found as already described for the desired output (/mountpoint/final_output.out):</p>
  <pre><code>user_id1;myORG_RESname1  
  user_id1;myORG_RESname2 
  </code></pre>
  <p>Using:</p>
  <p><code>tr '\n' ';' &lt; input_file &gt; output_file</code> doesn't give me the desired result...</p>
  <p>Any ideas how to achieve that? Any help is very much appreciated.</p>
  <p>EDIT:</p>
  <p>Here is the actual bash script I'm running for reference:</p>
  <pre><code>#!/bin/bash
  
  # assign file descriptor for input fd
  exec 3&lt; /mountpoint/userlist
  # assign file descriptor for output fd unfiltered
  exec 4&gt; /mountpoint/out_file_1.out
  # assign file descriptor for output fd filtered
  exec 5&gt; /mountpoint/out_file_2.out
  # assign file descriptor for output fd final
  exec 6&gt; /mountpoint/out_file_3.out
  
  while IFS= read -ru 3 LINE; do
      ldapsearch -h IPADDR -D &quot;uid=admin,cn=Users,ou=Department,dc=myDC&quot; -w somepwd &quot;(uid=$LINE)&quot; LDAPresource &gt;&amp;4
      grep -E '(^uid=|Resource1|Resource2|Resource3)' /mountpoint/out_file_1.out | cut -d, -f1 &gt;&amp;5
      grep -E 'TAMresource|uid=' /mountpoint/out_file_2.out | cut -d= -f2 &gt;&amp;6
      #tr '\n' ';' &lt; input_filename &gt; file
  done
  # close fd #3 inputfile
  exec 3&lt;&amp;-
  # close fd #4 &amp; 5 outputfiles
  exec 4&gt;&amp;-
  exec 5&gt;&amp;-
  # exit with 0 success status
  exit 0
  </code></pre>