Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

One possible way:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.