Turning multiple lines into one comma separated line

neversaint picture neversaint · Apr 2, 2013 · Viewed 140.9k times · Source

I have the following data in multiple lines:

foo
bar
qux
zuu
sdf
sdfasdf

What I want to do is to convert them to one comma separated line:

foo,bar,qux,zuu,sdf,sdfasdf

What's the best unix one-liner to do that?

Answer

Guru picture Guru · Apr 2, 2013

Using paste command:

paste -d, -s file