如何删除emacs中的重复行 [英] how to delete the repeat lines in emacs

查看:142
本文介绍了如何删除emacs中的重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本有很多行,我的问题是如何删除emacs中的重复行?使用emacs或elisp包中的命令,而不需要外部的utils。



例如:

 这是行a 
这是行b
这是行a

删除第三行(与第一行相同)

 这是行a 
这是行b


解决方案

将此代码放在.emacs中:

 (defun uniq-lines(beg end)
区域中的唯一行
从程序调用,有两个参数:
BEG和END(要排序的区域)​​
(interactiver)
(save-excursion
(save-restriction
-to-region beg end)
(goto-char(point-min))
(while(not(eobp))
(kill-line 1)
(yank)
(let((next-line(point)))
(而
(重新搜索转发
(格式为^%s(regexp-quote -ring)))nil t)
(替换匹配nil nil))
(goto-char next-line))))))

用法:

  Mx uniq-lines 


I have a text with a lots of lines, my question is how to delete the repeat lines in emacs? using the command in emacs or elisp packages without external utils.

for example:

this is line a
this is line b
this is line a

to remove the 3rd line (same as 1st line)

this is line a
this is line b

解决方案

Put this code to your .emacs:

(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))))))

Usage:

M-x uniq-lines

这篇关于如何删除emacs中的重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆