Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning multiple lines into one comma separated line [duplicate]

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?

like image 953
neversaint Avatar asked Apr 02 '13 07:04

neversaint


People also ask

How do I combine multiple lines in one?

The paste command can merge lines from multiple input files. By default, it merges lines in a way that entries in the first column belong to the first file, those in the second column are for the second file, and so on. The -s option can let it merge lines row-wise.


1 Answers

Using paste command:

paste -d, -s file 
like image 129
Guru Avatar answered Oct 02 '22 14:10

Guru