LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-07-2009, 11:58 AM   #1
resolute155
LQ Newbie
 
Registered: Dec 2006
Posts: 9

Rep: Reputation: 0
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!
 
Old 09-07-2009, 12:19 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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
 
Old 09-07-2009, 12:45 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Or even more simple:
Code:
tr ' ' '\n' < file
 
Old 09-07-2009, 02:29 PM   #4
resolute155
LQ Newbie
 
Registered: Dec 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Simple yet elegant, thank you both!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Transpose info between blocks from column to lines arragement cgcamal Programming 1 11-16-2008 08:48 PM
how to get the second column and first row data from a file??? loplayers Linux - Newbie 3 11-05-2007 07:35 PM
vi editor - how to delete a character in each row of a column? flipwhy Linux - Newbie 6 01-22-2007 02:12 PM
Transposing a column into a row mayyash Linux - General 1 09-30-2005 02:23 AM
How to write the contents of a column as a row in linux markraem Linux - Software 4 07-17-2004 07:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration