autodidacte
autodidacte

Reputation: 43

Loop for n lines - create csv

I've a text file that look likes this :

data1-1
data1-2
data1-3
data2-1
data2-2
data2-3
data3-1
data3-2
data3-3

And I want to transform it to a csv that look like :

data1-1,data1-2,data1-3
data2-1,data2-2,data2-3
data3-1,data3-2,data3-3

What is the best way to solve this problem? I can create my csv with with a echo command

echo "object1,object2,object3" > test.csv

But after that, I'm not sure about what is the best loop method. Please advise. Thanks.

Upvotes: 0

Views: 217

Answers (1)

Cyrus
Cyrus

Reputation: 88776

paste -d "," - - - <file >test.csv

Output to test.csv:

data1-1,data1-2,data1-3
data2-1,data2-2,data2-3
data3-1,data3-2,data3-3

Upvotes: 3

Related Questions