我有一个有很多行的文本,我的问题是如何删除emacs中的重复行?在不带外部实用程序的emacs或elisp包中使用命令。
例如:
this is line a
this is line b
this is line a
删除第3行(与第1行相同)
this is line a
this is line b
发布于 2012-10-24 18:03:46
将此代码放入您的.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))))))
用法:
M-x uniq-lines
发布于 2015-02-08 00:00:51
在linux中,选择region,然后键入
M-| uniq <RETURN>
没有重复的结果在新的缓冲区中。
https://stackoverflow.com/questions/13046791
复制相似问题