unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: gnuist006@gmail.com
Cc: help-gnu-emacs@gnu.org
Subject: Re: uniq without sort  <-------------- GURU NEEDED
Date: Fri, 25 Jan 2008 08:56:10 +0100	[thread overview]
Message-ID: <87lk6e9w4l.fsf@gmail.com> (raw)
In-Reply-To: <08698dfa-d5dc-484d-a5fb-fe84bb0d2893@s13g2000prd.googlegroups.com> (gnuist's message of "Thu, 24 Jan 2008 18:45:24 -0800 (PST)")

gnuist006@gmail.com writes:

> This is a tough problem, and needs a guru.
>
> I know it is very easy to find uniq or non-uniq lines if you scramble
> all of them and sort them. Its trivially
>
> echo -e "a\nc\nd\nb\nc\nd" | sort | uniq
>
> $ echo -e "a\nc\nd\nb\nc\nd"
> a
> c
> d
> b
> c
> d
>
> $ echo -e "a\nc\nd\nb\nc\nd"|sort|uniq
> a
> b
> c
> d
>
>
> So it is TRIVIAL with sort.
>
> 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.

Here in python but the same can be done in lisp or shell

In [13]: B = ["a", "c", "d", "b", "e", "a", "d", "e"]

In [14]: A = []

In [15]: for i in B:
   ....:     if i not in A: A.append(i)
   

In [16]: A

Out[16]: ['a', 'c', 'd', 'b', 'e']

-- 
A + Thierry
Pub key: http://pgp.mit.edu

  reply	other threads:[~2008-01-25  7:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-25  2:45 uniq without sort <-------------- GURU NEEDED gnuist006
2008-01-25  7:56 ` Thierry Volpiatto [this message]
2008-01-25  9:11 ` Peter Dyballa
     [not found] ` <slrnfpki57.7nj.andrews@sdf.lonestar.org>
     [not found]   ` <slrnfpkj9c.18qn.read_the_sig@mantell0.local>
     [not found]     ` <7d849d0c-9d8e-44e9-b461-38657fae0a7d@b2g2000hsg.googlegroups.com>
     [not found]       ` <5462c3ef-cb53-40d8-8a96-bbf624408300@v4g2000hsf.googlegroups.com>
2008-01-28 16:51         ` thermate
2008-01-29 13:16 ` Michele Dondi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lk6e9w4l.fsf@gmail.com \
    --to=thierry.volpiatto@gmail.com \
    --cc=gnuist006@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).