From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: gnuist006@gmail.com Newsgroups: gmane.emacs.help Subject: uniq without sort <-------------- GURU NEEDED Date: Thu, 24 Jan 2008 18:45:24 -0800 (PST) Organization: http://groups.google.com Message-ID: <08698dfa-d5dc-484d-a5fb-fe84bb0d2893@s13g2000prd.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1201232444 26852 80.91.229.12 (25 Jan 2008 03:40:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 25 Jan 2008 03:40:44 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jan 25 04:41:04 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JIFR9-0004I3-96 for geh-help-gnu-emacs@m.gmane.org; Fri, 25 Jan 2008 04:41:03 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JIFQj-0004Xu-3W for geh-help-gnu-emacs@m.gmane.org; Thu, 24 Jan 2008 22:40:37 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!s13g2000prd.googlegroups.com!not-for-mail Original-Newsgroups: comp.unix.questions, comp.unix.shell, gnu.emacs.help, comp.lang.c Original-Followup-To: comp.unix.shell Original-Lines: 42 Original-NNTP-Posting-Host: 75.28.103.223 Original-X-Trace: posting.google.com 1201229125 11276 127.0.0.1 (25 Jan 2008 02:45:25 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 25 Jan 2008 02:45:25 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s13g2000prd.googlegroups.com; posting-host=75.28.103.223; posting-account=REkl4woAAABFXaU7nL79XtGpnmNCQ415 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30),gzip(gfe),gzip(gfe) Original-Xref: shelby.stanford.edu comp.unix.questions:155216 comp.unix.shell:213681 gnu.emacs.help:155555 comp.lang.c:843705 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:50940 Archived-At: 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