Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transpose one line/lines from column to row using shell

Tags:

shell

unix

I want convert a column of data in a txt file to a row of a csv file using unix commands.

example:

ApplChk1,
ApplChk2,
v_baseLoanAmountTI,
v_plannedClosingDateField,
downPaymentTI,

this is a column which present in a txt file

I want output as follows in a csv file

ApplChk1,ApplChk2,v_baseLoanAmountTI,v_plannedClosingDateField,downPaymentTI,

Please let me know how to do it.

Thanks in advance

like image 589
lakshmi Avatar asked Feb 17 '26 08:02

lakshmi


1 Answers

If that's a single column, which you want to convert to row, then there are many possibilities:

tr -d '\n' < filename ; echo # option 1 OR
xargs echo -n < filename ; echo # option 2 (This option however, will shrink spaces & eat  quotes) OR
while read x; do echo -n "$x" ; done < filename; echo # option 3

Please let us know, how the input would look like, for multi-line case.

like image 109
anishsane Avatar answered Feb 20 '26 11:02

anishsane



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!