LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   transpose row to column? (https://www.linuxquestions.org/questions/programming-9/transpose-row-to-column-753352/)

resolute155 09-07-2009 11:58 AM

transpose row to column?
 
Hello,

I'm using Linux bash and trying to do the following:

I have a file with numerous numbers listed as a row, i.e.:

0.306885 -3.12756 -0.35022 -1.15112 -0.845154 -1.85443 -5.12708 5.23309



and I want to transpose them to a column, i.e.:

0.306885
-3.12756
-0.35022
-1.15112
-0.845154
-1.85443
-5.12708
5.23309


Anyone know the best way to do this?

Thanks!

David the H. 09-07-2009 12:19 PM

Assuming the file has just the one line, and nothing extra, then quick 'n dirty:
Code:

for x in $(cat inputfile.txt); do
 echo $x
done >outputfile.txt


colucix 09-07-2009 12:45 PM

Or even more simple:
Code:

tr ' ' '\n' < file

resolute155 09-07-2009 02:29 PM

Simple yet elegant, thank you both!


All times are GMT -5. The time now is 08:33 AM.