Concise and portable “join” on the Unix command-line

Perhaps a little surprisingly, paste is a good way to do this:

paste -s -d","

This won’t deal with the empty lines you mentioned. For that, pipe your text through grep, first:

grep -v '^$' | paste -s -d"," -

Leave a Comment