LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sort broken? (https://www.linuxquestions.org/questions/linux-newbie-8/sort-broken-507275/)

Jenc 12-03-2006 11:36 PM

sort broken?
 
Dear all,
something appears to have happened to sort
I have a file called "junk" with a whole lot of lines like this:

"N_A3F97.B99990010.pdb:REMARK 1 MODELLER OBJECTIVE FUNCTION: 1534.3015"

in a bash shell I try:
sort +5 -nr junk OR sort -nr +5 junk OR grep OBJECTIVE junk | sort -nr +5

I get:
sort: open failed: +5: No such file or directory

if I skip the "+5" it works fine but of course does not sort on the field I want it to

help
jenc

bigrigdriver 12-03-2006 11:57 PM

You can't make up options to commands; you are limited to the options as described in the man pages (or info pages). I don't see any option to pass agruments as signed numbers.

Try something like this:

cat junk | grep 'OBJECTIVE' | sort -nr

You could also use awk to read the file and select based on the content of specified field.

cat junk | awk '{print $5}' | sort -nr, or
awk '{print $5}' junk | sort -nr

or something along those lines.

Quakeboy02 12-04-2006 12:47 AM

"in a bash shell I try:
sort +5 -nr junk OR sort -nr +5 junk OR grep OBJECTIVE junk | sort -nr +5"

How about something like this?
sort --key=5 -n junk

Read the man pages again and give it another try.

Tinkster 12-04-2006 01:35 AM

What I don't understand is why one would want to sort a column
with the word "function" numerically...


Cheers,
Tink

makyo 12-04-2006 10:44 AM

Hi, Jenc.

You appear to be trying to use the old calling sequence for sort. For example, from the man page of Solaris 8 sort:
Quote:

+POS1 [-POS2]
Specify a field within each line to use as a sorting
key
And you may have been counting from the first field, which, in the old calling sequence, was "0", so you wanted to sort beginning with the sixth field.

However, you will likely need to use the new calling sequence:
Quote:

-k, --key=POS1[,POS2]
start a key at POS1, end it at POS 2 (origin 1)
See man sort for details -- it's not much of a change, you just need to get used to it ... cheers, makyo

Jenc 12-05-2006 04:22 PM

sort sorted
 
Thanks to all who replied esp mayo and Quakeboy02 who pointed out my real problem and reminded me to pay more careful attention to what is in the man page. using the updated version of the options worked a treat. I had been using the old way for years but hadn't used it for several months. now I will have to go and update all my scripts.

Ta very much
jenc


All times are GMT -5. The time now is 11:07 PM.