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

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

Re: How to implement line sorting, uniquifying and counting function in


From: Marc Spitzer
Subject: Re: How to implement line sorting, uniquifying and counting function in emacs?
Date: Mon, 30 Sep 2002 07:04:51 GMT
User-agent: Xnews/5.04.25

gnuist006@hotmail.com (gnuist006) wrote in 
b00bb831.0209291813.72d27e23@posting.google.com:">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


reply via email to

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