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

On Thu, 24 Jan 2008 18:45:24 -0800 (PST), gnuist006 [at] gmail.com wrote:

>I want uniq without sorting the initial order.
>
>The algorithm is this. For every line, look above if there is another
>line like it. If so, then ignore it. If not, then output it. I am
>sure, I can spend some time to write this in C. But what is the
>solution using shell ? This way I can get an output that preserves the
>order of first occurrence. It is needed in many problems.

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

perl -ne 'print unless $saw{$_}++' file

(And it's not even the most golfed down solution!)


Michele
--
Se, nella notte in cui concepi' il duce,
Donna Rosa, toccata da divina luce,
avesse dato al fabbro predappiano
invece della fica il deretano,
l'avrebbe presa in culo quella sera
Rosa sola e non l'Italia intera.
- Poesia antifascista
Michele Dondi [ Di, 29 Januar 2008 14:16 ] [ ID #1919465 ]
Perl » comp.lang.perl.misc » Re: uniq without sort <-------------- GURU NEEDED

Vorheriges Thema: FAQ 8.48 How do I add the directory my program lives in to the module/library search path?
Nächstes Thema: A do-file location: how the code inside that do-file find it?