BHAV247 BHAV247 - 7 months ago 59
Bash Question

How to convert text file to csv file using bash script

I have text file like this

data11
data12
data13
data14
data15
data21
data22
data23
data24
data25
.......


like this 2000 rows.

I want all these values in .csv file like

Image prob1 prob2 prob3 truevalue
data11 data12 data13 data14 data15
data21 data22 data23 data24 data25


can anybody provide a shell script for this??

Answer
 cat file|xargs -n5

works for the given example.

If this doesn't help, please tell the exact requirements.

update, add the fixed title

 cat <(echo "a b c d e") file|xargs -n5

if you want better format in output:

 cat <(echo "a b c d e") file|xargs -n5 |column -t
Comments