[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: delete double lines
From: |
Pascal Bourguignon |
Subject: |
Re: delete double lines |
Date: |
Fri, 11 Aug 2006 17:05:04 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
<C.Strobl@dlr.de> writes:
> hello all,
>
>
>
> is there any solution for delete double lines with emacs commands (or macros)?
>
>
>
> f.g.
>
>
>
> line1
>
> line1
>
> line2
>
> line1
>
> line2
>
>
>
> shall be processed to
>
>
>
> line1
>
> line2
>
>
>
>
>
> thanks and greetings from munich
>From emacs, I would select the range of lines, then type:
C-u M-| sort -u | sed -n -e p -e 's/.*//p' RET
If you want a pure emacs solution:
(require 'cl)
(defun sort-unique-lines-with-double-spacing (start end)
(interactive "r")
(save-excursion
(goto-char start)
(let ((lines '()))
(while (and (< (point) end) (re-search-forward "^\\(.*\\)$" end t))
(push (buffer-substring (match-beginning 0) (match-end 0)) lines))
(message "%S" lines)
(delete-region start end)
(dolist (line (sort (delete-duplicates lines :test (function string=))
(function string-lessp)))
(insert (format "%s\n\n" line))))))
Then you can select the range of lines,
and type M-x sort-unique-lines-with-double-spacing RET
--
__Pascal Bourguignon__ http://www.informatimago.com/
HEALTH WARNING: Care should be taken when lifting this product,
since its mass, and thus its weight, is dependent on its velocity
relative to the user.
- Re: delete double lines,
Pascal Bourguignon <=