LinuxQuestions.org
Register a domain and help support LQ
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 02-14-2008, 04:57 AM   #1
Ashok_mittal
Member
 
Registered: Dec 2007
Posts: 73

Rep: Reputation: 15
sort +1 -2 some.file


What is the use of +1

as -2 is the field from last?

Why we are giving this number here?
 
Old 02-14-2008, 07:09 AM   #2
atom
Member
 
Registered: Feb 2004
Location: Slovenia
Distribution: archlinux
Posts: 271

Rep: Reputation: 31
The answer can be found in the info directory:

Code:
$ info sort
Code:
`-k POS1[,POS2]'
`--key=POS1[,POS2]'
     Specify a sort field that consists of the part of the line between
     POS1 and POS2 (or the end of the line, if POS2 is omitted),
     _inclusive_.

     Each POS has the form `F[.C][OPTS]', where F is the number of the
     field to use, and C is the number of the first character from the
     beginning of the field.  Fields and character positions are
     numbered starting with 1; a character position of zero in POS2
     indicates the field's last character.  If `.C' is omitted from
     POS1, it defaults to 1 (the beginning of the field); if omitted
     from POS2, it defaults to 0 (the end of the field).  OPTS are
     ordering options, allowing individual keys to be sorted according
     to different rules; see below for details.  Keys can span multiple
     fields.

     Example:  To sort on the second field, use `--key=2,2' (`-k 2,2').
     See below for more examples.
Code:
   Scripts intended for use on standard hosts should avoid obsolete
syntax and should use `-k' instead.  For example, avoid `sort +2',
since it might be interpreted as either `sort ./+2' or `sort -k 3'.  If
your script must also run on hosts that support only the obsolete
syntax, it can use a test like `if sort -k 1 </dev/null >/dev/null
2>&1; then ...' to decide which syntax to use.
So... I'd say that it means "leave the 1st field alone" and "leave the last two fields alone", but in a deprecated syntax.
 
  


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
sort date in paragraphs within file nabmufti Programming 3 02-14-2008 11:13 AM
How sort data in some file which are greater than some value? sarajevo Programming 5 08-25-2006 04:48 AM
How can I sort the lines in a file? windhair Linux - Software 2 11-17-2005 09:37 AM
what sort of file attribute is this: b--Srws-wt BrianK Linux - General 6 12-18-2004 12:26 AM
Reverse Sort Text File BxBoy Linux - General 1 08-02-2004 11:13 AM


All times are GMT -5. The time now is 02:13 AM.

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