是否有可能在notepad++中删除重复的行,只留下一行的单一出现?


当前回答

notepad++有内置操作:

Edit -> Line Operations -> Sort Lines...
Edit -> Line Operations -> Remove Duplicate Lines

也许它只适用于删除重复行,但我需要通过看到排序工作来看到操作工作。

如果它不工作,问题可能是不同的结束线,我现在遇到的。您可以通过查看->显示符号->显示行结束来检查。 把它替换成相同的。

Click on Search > Replace (or Ctrl + H)
Find what:  \r\n
Replace with: \n
Search Mode: select Extended (\n, \r,...)
Replace All

其他回答

notepad++的后一个版本显然根本不包括TextFX插件。为了使用插件排序/消除重复,必须下载并安装插件(更复杂)或使用插件管理器添加插件。

A)简单的方法(如这里所述)。

插件->插件管理->显示插件管理->可用选项卡-> TextFX字符->安装

B)更复杂的方式,如果需要另一个版本或简单的方法不起作用。

从SourceForge下载插件: http://downloads.sourceforge.net/project/npp-plugins/TextFX/TextFX%20v0.26/TextFX.v0.26.unicode.bin.zip 打开压缩文件,解压“NppTextFX.dll” 将NppTextFX.dll放在notepad++插件目录中,例如: C:\Program Files\ notepad++ \ plugins 启动notepad++, TextFX将是文件菜单项之一(如Colin Pickard上面的答案#1所示)

在安装TextFX插件之后,按照答案#1中的说明对重复项进行排序和删除。

另外,如果你经常使用这个命令,或者想复制一个键盘快捷方式,比如在TextPad中使用F9进行排序,可以考虑使用Settings >快捷方式映射器来设置一个键盘快捷方式。

如果行是紧挨着的,那么你可以使用正则表达式替换:

搜索模式:^(.*\r?\n)(\1)+

替换为:\1

在NPP很难做到这一点。 更好的方法是:

下载cygwin实用程序,这是一个简单的Linux终端在windows下。 它允许在Windows中执行任何Linux命令。 这里是排序-u。

在7.8版中,您可以在没有任何插件的情况下完成这一点-编辑->行操作->删除连续重复的行。在此工作之前,您必须对文件进行排序,以便将重复的行按连续的顺序放置,但它确实非常有效。

排序选项可在编辑->行操作->排序按…

从notepad++版本6开始,你可以在搜索和替换对话框中使用这个正则表达式:

^(.*?)$\s+?^(?=.*^\1$)

什么都不替换。这将在所有重复行中留下文件中最后一次出现的内容。

不需要排序,重复的行可以在文件中的任何地方!

您需要勾选“正则表达式”和“正则表达式”选项。匹配换行符”:

^ matches the start of the line. (.*?) matches any characters 0 or more times, but as few as possible (It matches exactly on row, this is needed because of the ". matches newline" option). The matched row is stored, because of the brackets around and accessible using \1 $ matches the end of the line. \s+?^ this part matches all whitespace characters (newlines!) till the start of the next row ==> This removes the newlines after the matched row, so that no empty row is there after the replacement. (?=.*^\1$) this is a positive lookahead assertion. This is the important part in this regex, a row is only matched (and removed), when there is exactly the same row following somewhere else in the file.