9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] sort strangeness
@ 2009-09-27  7:54 Gregory Pavelcak
  2009-09-27  9:02 ` Tharaneedharan Vilwanathan
  2009-09-27  9:10 ` Richard Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Gregory Pavelcak @ 2009-09-27  7:54 UTC (permalink / raw)
  To: 9fans

Just noticed this

cpu% cat tmp/sorttest
2
7
2.1
2.1.4
2.1.1
cpu% sort tmp/sorttest
2
2.1
2.1.1
2.1.4
7
cpu% sort -u tmp/sorttest
2
2.1
2.1.1
2.1.4
7
cpu% sort -n tmp/sorttest
2
2.1
2.1.4
2.1.1
7
cpu% sort -n -u tmp/sorttest
2
2.1
7
cpu%


Greg



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] sort strangeness
  2009-09-27  7:54 [9fans] sort strangeness Gregory Pavelcak
@ 2009-09-27  9:02 ` Tharaneedharan Vilwanathan
  2009-09-27 13:42   ` Gregory Pavelcak
  2009-09-27  9:10 ` Richard Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Tharaneedharan Vilwanathan @ 2009-09-27  9:02 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

hi,

doesnt it seem to be fine?

> Just noticed this
>
> cpu% cat tmp/sorttest
> 2
> 7
> 2.1
> 2.1.4
> 2.1.1
> cpu% sort tmp/sorttest
> 2
> 2.1
> 2.1.1
> 2.1.4
> 7
------> sorts the string values
> cpu% sort -u tmp/sorttest
> 2
> 2.1
> 2.1.1
> 2.1.4
> 7
------> sorts the string values and removes any duplicates (none here)
> cpu% sort -n tmp/sorttest
> 2
> 2.1
> 2.1.4
> 2.1.1
> 7
-----> sorts the numeric values (which is an integer or floating-point
value of format x.y)
In this case 2.1.4 is treated as 2.1 (ignores second "." and following
characters)

> cpu% sort -n -u tmp/sorttest
> 2
> 2.1
> 7
----> sorts the numeric values (which is an integer or floating-point
value of format x.y)
and removes any duplicates. In this case, 2.1, 2.1.4 and 2.1.1 are all
2.1, so removes
duplicates.

or, am i missing something?

thanks
dharani



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] sort strangeness
  2009-09-27  7:54 [9fans] sort strangeness Gregory Pavelcak
  2009-09-27  9:02 ` Tharaneedharan Vilwanathan
@ 2009-09-27  9:10 ` Richard Miller
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Miller @ 2009-09-27  9:10 UTC (permalink / raw)
  To: 9fans

You probably want it to look at the rest of the line after sorting
according to the initial numeric string, like this:

cpu% cat tmp/sorttest
2
7
2.1
2.1.4
2.1.1
term% sort +0n +1 -t. -u tmp/sorttest
2
2.1
2.1.1
2.1.4
7

I think the "strangeness" you observed is consistent with what
the man page says:

          -n   An initial numeric string, consisting of optional white
               space, optional plus or minus sign, and zero or more
               digits with optional decimal point, is sorted by arith-
               metic value.
          -u         Suppress all but one in each set of equal lines.
                     Ignored bytes and bytes outside keys do not par-
                     ticipate in this comparison.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] sort strangeness
  2009-09-27  9:02 ` Tharaneedharan Vilwanathan
@ 2009-09-27 13:42   ` Gregory Pavelcak
  0 siblings, 0 replies; 4+ messages in thread
From: Gregory Pavelcak @ 2009-09-27 13:42 UTC (permalink / raw)
  To: 9fans

I think you and Richard are right. Looking at the man page,
the behavior is not unexpected. I mis-read what my own
experiment did and thought sort -n actually sorted 2.1.4
and 2.1.1.  I guess it's more of a 4am-on-a-sleepless-night
problem than a sort problem.

Thanks.

Greg



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-09-27 13:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-27  7:54 [9fans] sort strangeness Gregory Pavelcak
2009-09-27  9:02 ` Tharaneedharan Vilwanathan
2009-09-27 13:42   ` Gregory Pavelcak
2009-09-27  9:10 ` Richard Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).