From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michele Dondi Newsgroups: gmane.emacs.help Subject: Re: uniq without sort <-------------- GURU NEEDED Date: Tue, 29 Jan 2008 14:16:28 +0100 Organization: Aioe.org NNTP Server Message-ID: <6j9up39qkqe5oolbeoammmiq6hp0vqa5de@4ax.com> References: <08698dfa-d5dc-484d-a5fb-fe84bb0d2893@s13g2000prd.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1201614054 16043 80.91.229.12 (29 Jan 2008 13:40:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Jan 2008 13:40:54 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 29 14:41:09 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 1JJqhy-0001XJ-Tt for geh-help-gnu-emacs@m.gmane.org; Tue, 29 Jan 2008 14: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 1JJqhX-0006DY-VX for geh-help-gnu-emacs@m.gmane.org; Tue, 29 Jan 2008 08:40:35 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!goblin1!goblin.stu.neva.ru!news.mixmin.net!aioe.org!not-for-mail Original-Newsgroups: comp.unix.questions, comp.unix.shell, gnu.emacs.help, comp.lang.c, comp.lang.perl.misc Original-Followup-To: comp.lang.perl.misc Original-Lines: 26 Original-NNTP-Posting-Host: +o1wq0SZxXV/apoZyCQ8zA.user.aioe.org Original-X-Complaints-To: abuse@aioe.org X-Newsreader: Forte Agent 2.0/32.652 Original-Xref: shelby.stanford.edu comp.unix.questions:155247 comp.unix.shell:213831 gnu.emacs.help:155670 comp.lang.c:844482 comp.lang.perl.misc:622847 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:51051 Archived-At: On Thu, 24 Jan 2008 18:45:24 -0800 (PST), gnuist006@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