Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a bash ldapsearch in a while loop what I want to write to a csv file. The ldap listing looks like this:

ou=..,dc=..
data1
out=..,dc=..
data2

My goal is this format in the csv file:

ou=..,dc=..,data1
ou=..,dc=..,data2

The problem is with the tr '\n' ',' where it changes the newline, but because of the loop it changes everwhere, causing this:

ou=..,dc=..,data1,ou=..,dc=..,data2,

How can I replace the newline only before the data?

share|improve this question
1  
Please at least make sure your question looks properly formatted when posted – the original had all three examples looking identical. The site even has a preview box... – grawity Mar 16 '12 at 20:57

One possible way:

while read -r dn && read -r data; do
    echo "$dn,$data"
done
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .