From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Marc Spitzer Newsgroups: gmane.emacs.help Subject: Re: How to implement line sorting, uniquifying and counting function in emacs? Date: Mon, 30 Sep 2002 07:04:51 GMT Organization: Optimum Online Sender: help-gnu-emacs-admin@gnu.org Message-ID: References: NNTP-Posting-Host: localhost.gmane.org X-Trace: main.gmane.org 1033370176 4302 127.0.0.1 (30 Sep 2002 07:16:16 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 30 Sep 2002 07:16:16 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17vums-00017F-00 for ; Mon, 30 Sep 2002 09:16:15 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17vun5-0004DF-00; Mon, 30 Sep 2002 03:16:27 -0400 Original-Path: shelby.stanford.edu!nntp.stanford.edu!newsfeed.stanford.edu!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!snoopy.risq.qc.ca!ps01-chi1!rip!newsfeeds-atl1.usenetserver.com!news.webusenet.com!pc01.webusenet.com!news4.srv.hcvlny.cv.net.POSTED!53ab2750!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.lang.lisp,gnu.utils.help,comp.unix.shell,comp.unix.programmer Original-Followup-To: gnu.emacs.help,comp.lang.lisp User-Agent: Xnews/5.04.25 Original-Lines: 41 Original-NNTP-Posting-Host: 24.184.104.202 Original-X-Trace: news4.srv.hcvlny.cv.net 1033369491 24.184.104.202 (Mon, 30 Sep 2002 03:04:51 EDT) Original-NNTP-Posting-Date: Mon, 30 Sep 2002 03:04:51 EDT Original-Xref: nntp.stanford.edu gnu.emacs.help:105528 comp.lang.lisp:94998 gnu.utils.help:4060 comp.unix.shell:133594 comp.unix.programmer:143541 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:2072 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:2072 gnuist006@hotmail.com (gnuist006) wrote in news:b00bb831.0209291813.72d27e23@posting.google.com: > In shell you can do this: > > cat file | sort | uniq -d | wc > > to count the repeated lines. You can also do > > cat file | sort | uniq -u | wc > > to count the unique lines. > > Sometimes I have to do this on windows platform where I do have emacs. > This means that I cannot escape to shell and that route is not available. > > Lisp has sort-lines, but no uniq -u or uniq -d available. Also I do not > know the equivalent to wc. > > This is where some help is requested. I think that this is not only a > problem of lisp programming, but also algorithms. Which group has this > kind of expertise? > > Cheers! > gnuist > if elisp has hashes do the following: 1: open file 2: for each line set it as the key of the hash and add 1 to the previous value, first time set it to 1 3a: for the uniq -u count the number of keys 3b: for the uniq -d for each value > 1 add it to a total then print the total 3c: for the truely uniq lines, value == 1, count the number of keys who have a value == 1 and print marc