Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-04-2006, 12:36 AM   #1
LQ Newbie
Registered: May 2006
Posts: 3

Rep: Reputation: 0
Unhappy 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

Old 12-04-2006, 12:57 AM   #2
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
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.

Last edited by bigrigdriver; 12-04-2006 at 01:11 AM.
Old 12-04-2006, 01:47 AM   #3
Senior Member
Registered: Nov 2006
Distribution: Debian Linux 9 (stretch)
Posts: 3,360

Rep: Reputation: 127Reputation: 127
"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.
Old 12-04-2006, 02:35 AM   #4
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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

Old 12-04-2006, 11:44 AM   #5
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 732

Rep: Reputation: 75
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:
+POS1 [-POS2]
Specify a field within each line to use as a sorting
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:
-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
Old 12-05-2006, 05:22 PM   #6
LQ Newbie
Registered: May 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Thumbs up 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



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
Is there a line limit with the sort utility? Trying to sort 130 million lines of text gruffy Linux - General 4 08-10-2006 09:40 PM
sort +r ?? ravi.ravix Linux - General 1 07-07-2006 10:52 AM
C++ Sort() bendeco13 Programming 2 11-03-2005 12:26 AM
iwlist broken by kernel upgrade....Sort of Hangdog42 Linux - Wireless Networking 2 09-14-2005 09:17 PM
sort pantera Programming 5 05-26-2004 08:36 PM > Forums > Linux Forums > Linux - Newbie

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

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