LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash sort problem (https://www.linuxquestions.org/questions/programming-9/bash-sort-problem-723202/)

ArthurHuang 05-02-2009 04:14 PM

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!

pixellany 05-02-2009 04:27 PM

It works here.....

Try it without the redirection---sort -k5 input.txt

ArthurHuang 05-02-2009 04:41 PM

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 (Post 3528003)
It works here.....

Try it without the redirection---sort -k5 input.txt


bigearsbilly 05-02-2009 04:45 PM

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.

ArthurHuang 05-02-2009 05:20 PM

Yeah, i think it is because numerical numbers.
Thank you very much.


Quote:

Originally Posted by bigearsbilly (Post 3528013)
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.



All times are GMT -5. The time now is 03:32 PM.