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


当前回答

Notepad + +

->替换window

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

找到:

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

替换为:

$1

之前:

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

后:

我们认为 一行 有可能

其他回答

在notepad++ 8.1版本中,有一个特定的命令可以精确地完成这个流行问题的要求。On可以使用菜单命令“编辑>行操作>删除重复行”删除文本文件中的重复行。

不需要安装插件(正如目前接受的答案所建议的那样),也不需要事先对行进行排序,或者像其他答案所建议的那样在Replace对话框中使用regex语法。

搜索正则表达式:\b(\w+)\b([\w\ w]*)\b\1\b

替换为:$1$2

点击“替换”按钮,直到文件中不再匹配正则表达式为止。

你可能需要一个插件来做到这一点。您可以尝试ConyEdit的命令行cc.ddl(删除重复的行)。它是一个文本编辑器的跨编辑器插件,包括notepad++。

使用ConyEdit在后台运行,遵循以下步骤:

在文本末尾输入命令行cc.ddl。 复制文本和命令行。 粘贴,然后你会看到你想要的。

例子

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