LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 01-12-2009, 07:28 AM   #1
bioinformatics_guy
Member
 
Registered: Aug 2008
Posts: 54

Rep: Reputation: 15
Multiple field sort (quick explanation)


Lets say I had a file of the following form:

a 0 0
a 0 1
a 1 0
a 1 1
b 0 0
b 0 1
b 1 0
b 1 1

And I want to sort first by the 2nd column and then by the first column.

I know that the command is:

sort +1 -2 +0 -1 <filename>

but my question is, I know the +1 means sort by the second column but what does the -2 mean? Same with +0 -1. Why can't I just put:

sort +1 +0 <filename>

Which I would expect to sort by the second column and if thats the same sort by the first; which is not correct.
 
Old 01-12-2009, 07:31 AM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,735
Blog Entries: 27

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Hi,

Smells like homework to me!

You could 'man sort'.
 
Old 01-12-2009, 07:55 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Where are you getting that syntax? It does not appear in the man page.
 
Old 01-12-2009, 09:09 AM   #4
bioinformatics_guy
Member
 
Registered: Aug 2008
Posts: 54

Original Poster
Rep: Reputation: 15
I found it on some Unix help documentation online. Apparently, it is the old syntax. The equivalent is:

sort -k2,2 -k1,1 <Filename>

which seems to make more sense as the index starts at 1, the first number is what field to start and the second is which field to stop at (include that field).
 
  


Reply


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
quick hand with awk multiple field separators pld Programming 10 05-28-2010 07:51 AM
A Quick Explanation on How to Network 2 Linux PCs maryam11 Linux - Networking 1 08-06-2006 02:44 AM
Sort File by Field - but with a Twist! ;) moo-cow Programming 8 06-12-2006 11:26 AM
need explanation of multiple user/group Q's a2tech Linux - Newbie 1 07-27-2005 01:18 PM
I need a quick explanation of Linux video and audio... shah1701 Linux - General 2 10-05-2004 12:21 PM


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