LinuxQuestions.org
Help answer threads with 0 replies.
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 05-02-2009, 04:14 PM   #1
ArthurHuang
Member
 
Registered: Jan 2006
Posts: 174

Rep: Reputation: 30
bash sort problem


I have a input.txt file contains format like this:

35 245 0.885000 0.785000 4.730193 60.00
35 245 0.885000 0.780000 4.760514 60.00
35 245 0.885000 0.775000 4.791227 60.00
35 245 0.885000 0.770000 4.206335 58.18
35 245 0.885000 0.765000 4.233828 58.18
35 245 0.885000 0.760000 4.261681 58.18
35 245 0.885000 0.755000 4.289903 58.18
35 245 0.885000 0.750000 4.318504 58.18
35 245 0.885000 0.745000 4.347486 58.18
35 245 0.885000 0.740000 4.376862 58.18
35 245 0.885000 0.735000 4.183954 58.18
35 245 0.885000 0.730000 4.212610 58.18
35 245 0.885000 0.725000 4.241663 58.18
...
...
...

Now I want to sort the text file by the 5th column, I use the command

sort -k5 input.txt>temp

but it doesn't work, I mean the 5th column is not sorted.
Anyone knows why? Thanks a lot!
 
Old 05-02-2009, 04:27 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
It works here.....

Try it without the redirection---sort -k5 input.txt
 
Old 05-02-2009, 04:41 PM   #3
ArthurHuang
Member
 
Registered: Jan 2006
Posts: 174

Original Poster
Rep: Reputation: 30
I have to redirect the result into another file.
Because the input file is too large to read within scroll bar.
Quote:
Originally Posted by pixellany View Post
It works here.....

Try it without the redirection---sort -k5 input.txt
 
Old 05-02-2009, 04:45 PM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,284

Rep: Reputation: 172Reputation: 172
works for me too.
what uname -a?

maybe try -k5,6

also, for numeric sorts you should use n

sort -k5n

or you might get tripped up later if different field widths.
 
Old 05-02-2009, 05:20 PM   #5
ArthurHuang
Member
 
Registered: Jan 2006
Posts: 174

Original Poster
Rep: Reputation: 30
Yeah, i think it is because numerical numbers.
Thank you very much.


Quote:
Originally Posted by bigearsbilly View Post
works for me too.
what uname -a?

maybe try -k5,6

also, for numeric sorts you should use n

sort -k5n

or you might get tripped up later if different field widths.
 
  


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
bash regex - sort czezz Programming 3 02-05-2009 07:41 PM
Need help with bash script /simplified sort command/ szcs Linux - General 0 10-26-2008 11:40 AM
bash sort files by date in file name thedude2010 Programming 6 05-12-2006 11:07 AM
bash script to sort files by extension otheralex Programming 7 08-19-2005 02:40 AM
How to loop or sort in bash, awk or sed? j4r0d Programming 1 09-09-2004 03:22 AM


All times are GMT -5. The time now is 04:14 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration