Ancient sort version?

Mike Kupfer m.kupfer at acm.org
Mon Aug 5 18:56:02 UTC 2013


Kevin O'Gorman wrote:

> >  if grep -v "^: " < "$nlist" | sort +2 | uniq > "$nlist"S; then
> where the sort step was complaining about the "+2" command-line option.
> 
> Does anybody recollect sort(1) ever taking such an option, and if so
> what it meant?

Yes, this is the old sort key syntax.  "info sort" explains it thusly:

--8<---------------cut here---------------start------------->8---
   On older systems, `sort' supports an obsolete origin-zero syntax
`+POS1 [-POS2]' for specifying sort keys.  The obsolete sequence `sort
+A.X -B.Y' is equivalent to `sort -k A+1.X+1,B' if Y is `0' or absent,
otherwise it is equivalent to `sort -k A+1.X+1,B+1.Y'.

   This obsolete behavior can be enabled or disabled with the
`_POSIX2_VERSION' environment variable (*note Standards conformance::);
it can also be enabled when `POSIXLY_CORRECT' is not set by using the
obsolete syntax with `-POS2' present.
--8<---------------cut here---------------end--------------->8---

So "sort +2" is equivalent to "sort -k 3".

cheers,
mike




More information about the ubuntu-users mailing list