LinuxQuestions.org
Help answer threads with 0 replies.
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 12-04-2006, 12:36 AM   #1
Jenc
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

help
jenc
 
Old 12-04-2006, 12:57 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
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
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,275

Rep: Reputation: 126Reputation: 126
"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
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

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


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

Rep: Reputation: 74
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
 
Old 12-05-2006, 05:22 PM   #6
Jenc
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
jenc
 
  


Reply

Tags
sort


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


All times are GMT -5. The time now is 04:19 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