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


当前回答

如果你不关心行顺序(我认为你不关心),那么你可以使用Linux/FreeBSD/Mac OS X/Cygwin盒子,然后做:

$ cat yourfile | sort | uniq > yourfile_nodups

然后在notepad++中再次打开该文件。

其他回答

notepad++的插件管理器目前不可用(不随发行版提供)。你必须手动安装它(https://github.com/bruderstein/nppPluginManager/releases),即使你这样做,很多插件是不可用的(没有TextFX)插件。

也许有另一个插件包含所需的功能。除此之外,在notepad++中做到这一点的唯一方法是使用一些特殊的正则表达式进行匹配,然后替换(Ctrl + F→替换选项卡)。

虽然有许多功能可通过编辑菜单项(修剪,删除空行,排序,转换EOL),但没有“唯一”操作可用。

如果你有Windows 10,那么你可以启用Bash(只需在微软商店中输入Ubuntu,并按照说明安装它),并使用cat your_file.txt | sort | uniq > your_file_editing .txt。当然,你必须在与“your_file.txt”相同的工作目录中,或者通过它的路径引用它。

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

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

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

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

替换为:$1$2

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

如果你不关心行顺序(我认为你不关心),那么你可以使用Linux/FreeBSD/Mac OS X/Cygwin盒子,然后做:

$ cat yourfile | sort | uniq > yourfile_nodups

然后在notepad++中再次打开该文件。