LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-21-2011, 11:59 AM   #1
msbstar
Member
 
Registered: Jan 2010
Distribution: Ubuntu 10.4
Posts: 122

Rep: Reputation: 16
Question How to Sort Columns of Data (descending to ascending)?


Hello Everybody,

I have an ASCII file containing 3 Columns of descending data as
flollows:
.
.
.
3277.233 | 9.032167E-16 | 5.354040E-16
3276.725 | 1.825813E-15 | 7.552098E-16
3276.211 | 2.472245E-15 | 8.826818E-16
3275.699 | 2.943001E-16 | 3.192112E-16
3275.188 | 1.921011E-15 | 5.618553E-16
3274.677 | 1.089351E-15 | 4.211239E-16
.
.
.

I want to sort them in ascending order.

Does anybody know how to do it in Ubuntu 10.4.

I would be very grateful for any help.

With best regards,
Hassan

Last edited by msbstar; 03-21-2011 at 12:02 PM.
 
Old 03-21-2011, 12:01 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,185

Rep: Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586
Code:
sort filename
If thats not what you want:
Code:
sort --reverse filename

Last edited by szboardstretcher; 03-21-2011 at 12:02 PM.
 
1 members found this post helpful.
Old 03-21-2011, 12:04 PM   #3
msbstar
Member
 
Registered: Jan 2010
Distribution: Ubuntu 10.4
Posts: 122

Original Poster
Rep: Reputation: 16
Thanks,

But how can I save it in a new file?

thanks
 
Old 03-21-2011, 12:04 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
If the file is already sorted, the problem reduces to reversing the file:
Code:
tac file
 
1 members found this post helpful.
Old 03-21-2011, 12:05 PM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,185

Rep: Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586
Quote:
Originally Posted by msbstar View Post
Thans,

But how can I save it in a new file?

thanks
Code:
sort filename > newfilename.txt

sort -r filename > newfilename.txt

tac filename > newfilename.txt
 
1 members found this post helpful.
Old 03-21-2011, 12:08 PM   #6
msbstar
Member
 
Registered: Jan 2010
Distribution: Ubuntu 10.4
Posts: 122

Original Poster
Rep: Reputation: 16
Thanks Everyone for Helping.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Ascending or descending order for poll results? linuxlover.chaitanya LQ Suggestions & Feedback 3 02-09-2011 11:24 PM
[SOLVED] Sort in descending order according to a column of an array flea89 Linux - Newbie 3 03-14-2010 06:00 PM
[SOLVED] [Perl] fail to sort a file with 300,000 lines by multiple columns Kunsheng Programming 10 11-13-2009 06:41 PM
sort by multiple columns wakatana Linux - Newbie 5 10-18-2009 03:35 PM
php sort help - sort numerical descending then by alphabetical? RavenLX Programming 3 03-11-2009 08:35 AM


All times are GMT -5. The time now is 08: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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration