LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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-03-2006, 11:36 PM   #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-03-2006, 11:57 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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 12:11 AM.
 
Old 12-04-2006, 12:47 AM   #3
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
"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, 01:35 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 10:44 AM   #5
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
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, 04: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



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 08:40 PM
sort +r ?? ravi.ravix Linux - General 1 07-07-2006 09:52 AM
C++ Sort() bendeco13 Programming 2 11-02-2005 11:26 PM
iwlist broken by kernel upgrade....Sort of Hangdog42 Linux - Wireless Networking 2 09-14-2005 08:17 PM
sort pantera Programming 5 05-26-2004 07:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:24 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
Open Source Consulting | Domain Registration