Sed processes line by line; therefore, special syntax is needed to replace the newline char. For some darn reason, I keep forgetting this special syntax. Here is the command to replace newlines with a comma:
sed ':a;N;$!ba;s/\n/,/g'
I got this code from this Stack Overflow question.
Update [2015-11-16]: If the idea is to drop / skip empty lines, you can use grep:
grep -v -e "^$"
Careful not to be fooled by white chars. If you also want to drop lines that have only white chars, you can use:
grep -v -e '^[[:space:]]*$'
I got the above tip from another Stack Overflow question.