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


当前回答

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

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

其他回答

无论文件是否排序,您都可以使用下面的regex删除文件中任何位置的重复项。

^([^\r]*[^\n])(.*?)\r?\ n \ 1美元 替换为:\1\2 搜索模式:

“正则表达式” 检查“。匹配换行"选项

尽可能多地点击“替换全部”(或按住Alt+A快捷键),直到你看到“0次发生被替换”

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 + +

->替换window

确保在搜索模式中选择了正则表达式单选按钮

找到:

(*) ^ (r ? (n - 1) +美元

替换为:

$1

之前:

我们认为 我们认为 一行 有可能 有可能

后:

我们认为 一行 有可能

从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.

带有TextFX插件的notepad++可以做到这一点,如果你想按行排序,并同时删除重复的行。

要在最新版本的notepad++中安装TextFX,您需要从这里下载:https://sourceforge.net/projects/npp-plugins/files/TextFX

TextFX插件曾经包含在旧版本的notepad++中,或者可以从菜单中添加到插件->插件管理器->显示插件管理器->可用选项卡-> TextFX ->安装。在某些情况下,它也可能被称为TextFX字符,但这是同样的事情。

需要的复选框和按钮现在将出现在菜单下:TextFX -> TextFX工具。

确保选中了“sort outputs only unique…”。接下来,选择一个文本块(Ctrl+ a选择整个文档)。最后,点击“区分大小写排序”或“不区分大小写排序”