首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何删除emacs中的重复行

如何删除emacs中的重复行
EN

Stack Overflow用户
提问于 2012-10-24 17:53:13
回答 2查看 8.8K关注 0票数 26

我有一个有很多行的文本,我的问题是如何删除emacs中的重复行?在不带外部实用程序的emacs或elisp包中使用命令。

例如:

代码语言:javascript
复制
this is line a
this is line b
this is line a

删除第3行(与第1行相同)

代码语言:javascript
复制
this is line a
this is line b
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-24 18:03:46

将此代码放入您的.emacs:

代码语言:javascript
复制
(defun uniq-lines (beg end)
  "Unique lines in region.
Called from a program, there are two arguments:
BEG and END (region to sort)."
  (interactive "r")
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (while (not (eobp))
        (kill-line 1)
        (yank)
        (let ((next-line (point)))
          (while
              (re-search-forward
               (format "^%s" (regexp-quote (car kill-ring))) nil t)
            (replace-match "" nil nil))
          (goto-char next-line))))))

用法:

代码语言:javascript
复制
M-x uniq-lines
票数 19
EN

Stack Overflow用户

发布于 2015-02-08 00:00:51

在linux中,选择region,然后键入

代码语言:javascript
复制
M-| uniq <RETURN>

没有重复的结果在新的缓冲区中。

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13046791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档