[GRASS-user] List of existing values
Nikos Alexandris
nikos.alexandris at felis.uni-freiburg.de
Sat Aug 7 19:34:31 EDT 2010
On Friday 23 of July 2010 08:58:09 Nikos Alexandris wrote:
> Martin Landa wrote:
> > > > > as mentioned in Hamish's response, use combination of
> > > > > `sort` and `uniq`
> > > > > r.starts -1 input=data | sort | uniq
>
> Nikos:
> > > > shorter:
> > > > r.starts -1 input=data | sort -u
>
> Hamish:
> > > AFAIR, those are not the same thing and can not be used
> > > interchangeably. (although I don't fully remember why right now)
>
> Nikos:
> > It has troubled me as well (now and in the past). I did (before posting
> > the above) a quick test using a column from a vector map containing
> > strings. I counted the result from both "uniq" and "sort -u" with "| wc
> > -l". The results were identical.
> >
> > So... :-? Maybe it is ok for strings/integers(?). One should be more
> > careful with those "knifes".
>
> Hamish:
> > > anyway, for floating point maps I still think it's a bad idea.
> > >
> > > I'm sure there is a Python equivalent of 'sort|uniq', but don't
> > > know what it is.
> > >
> > > 'sort' and 'uniq' are UNIX command line power tools and not
> > > available in MS Windows. But.. the MSys command prompt that
> > > ships with WinGrass supplies them and you can use them there.
> > > I suppose the "bin" dir where they are kept are not part of the
> > > gui's PATH which is why they wouldn't work from the Cmd> gui
> > > prompt.
>
> Here some details from "(coreutils.info.gz)sort invocation":
>
> --%<---
> `-u'
> `--unique'
> Normally, output only the first of a sequence of lines that compare
> equal. For the `--check' (`-c' or `-C') option, check that no
> pair of consecutive lines compares equal.
>
> This option also disables the default last-resort comparison.
>
> The commands `sort -u' and `sort | uniq' are equivalent, but this
> equivalence does not extend to arbitrary `sort' options. For
> example, `sort -n -u' inspects only the value of the initial
> numeric string when checking for uniqueness, whereas `sort -n |
> uniq' inspects the entire line. *Note uniq invocation::.
> --->%--
And something more from "man uniq" (a reminder to avoid using "uniq" on its
own):
--%<---
Note: 'uniq' does not detect repeated lines unless they are adjacent. You may
want to
sort the input first, or use `sort -u' without `uniq'. Also,
comparisons honor the
rules specified by `LC_COLLATE'.
-->%---
Nikos
More information about the grass-user
mailing list