Re: uniq without sort <-------------- GURU NEEDED



Michael Tosch <eedmit@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Michele Dondi wrote:
On Thu, 24 Jan 2008 18:45:24 -0800 (PST), gnuist006@xxxxxxxxx wrote:
I want uniq without sorting the initial order.

In shell I don't know. In Perl it's well known to be as trivial as

perl -ne 'print unless $saw{$_}++' file
[...]
This is "print first unique".
For "print last unique" you really need perl:

perl -ne '$s{$_}=++$i; END {print sort {$s{$a}<=>$s{$b}} keys %s}'

Or just read slurp the whole file into an array, reverse(), and then use
Michele's suggestion.

jue
.



Relevant Pages

  • Re: Help: Reverse Letters
    ... If that is the case then just slurp in the whole file into a single ... string and reverse that string. ... once on the array and once on each element of the ...
    (comp.lang.perl.misc)
  • Re: solaris rev utility
    ... that's probably the easiest solution. ... > Or use perl: ... You don't need an array as reverse works on scalars as well. ...
    (comp.unix.programmer)
  • Re: Learning Perl
    ... it should be an array, ... Then they'd be completely inaccessible to beginners. ... that should be my $var. ... so why is it redundant to point out that Perl is different from C here? ...
    (comp.lang.perl.misc)
  • Re: perl vs Unix grep
    ... variable indexCount on array and reintialized evry time. ... Perl is langauge to make things work at any cost. ... > grep but the shell scripts that use ... As far as I can tell from reading and research ...
    (comp.lang.perl)
  • FAQ 4.42 How can I tell whether a certain element is contained in a list or array?
    ... comes with the standard Perl distribution. ... How can I tell whether a certain element is contained in a list or array? ... used a hash, not a list or array, to store your data. ... The perlfaq-workers, a group of volunteers, maintain the perlfaq. ...
    (comp.lang.perl.misc)