How to Convert rows in to columns?

Hi Gurus,

How to convert rows in to columns using linux shell scripting

Input is like (sample.txt)

ABC
DEF
GHI
JKL
MNO
PQR
STU
VWX
YZA
BCD

output should be (sampleoutput.csv)

ABC,DEF,GHI,JKL,MNO
PQR,STU,VWX,YZA,BCD

After a specified row (for example after 5 rows) out put should be redirected to new line.

Thanks in advance...

awk 'BEGIN{FS=","}c!=5{ORS=FS;c++}c==5{ORS=RS;c=0}1' sample.txt

try also:

paste -d, - - - - - < sample.txt > sampleoutput.csv
3 Likes