help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

uniq without sort <-------------- GURU NEEDED


From: gnuist006
Subject: uniq without sort <-------------- GURU NEEDED
Date: Thu, 24 Jan 2008 18:45:24 -0800 (PST)
User-agent: G2/1.0

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.

Thanks to the star who can help
gnuist










reply via email to

[Prev in Thread] Current Thread [Next in Thread]