notepad++ - 如何删除重复行(文本文件)?

标签 notepad++ lines

今天我试图删除一个简单文本文件中的重复行,例如:

input (list.txt):

hello
hello
try

output (list.txt):
try

我尝试使用 Notepad++ 删除重复的行并删除剩余的行,但什么也没有。 有没有软件或某些功能可以用 Notepad++ 执行此操作?

谢谢。

最佳答案

假设文件已排序,将所有重复行放在一起。

  • Ctrl+H
  • 查找内容:^(.+(?:\R|$))\1+
  • 替换为:LEAVE EMPTY
  • 选中环绕
  • 检查正则表达式
  • 请勿检查。匹配换行符
  • 全部替换

说明:

^           : beginning of line
  (         : start group 1
    .+      : 1 or more any character but newline
    (?:     : start non capture group
      \R    : any kind of linebreak
     |      : OR
      $     : end of line
    )       : end group
  )         : end group 1
  \1+       : back-reference to group 1, may appear 1 or more times

给定示例的结果:

try

关于notepad++ - 如何删除重复行(文本文件)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48039999/

相关文章:

python - 如何读取一个文本文件的前N行并将其写入另一个文本文件?

正则表达式,用于在 | 之后删除所有内容(带 | )

regex - 正则表达式匹配单词边界,但排除具有任何前缀或后缀的单词

javascript - 我无法在 Notepad++ 上运行javascript

notepad++ - Notepad++ 中代码折叠的自定义区域

c++ - 霍夫变换后如何只过滤最长的线

regex - Notepad++ 正则表达式查找并替换 : Match-but-dont-include operator ? <= 不起作用。为什么?

sed - 单行删除特定字符出现次数超过 x 次的行

c - 当两行为空时尝试使用 fgets() 停止我的程序

python - 在读取 Python 文件中的行时跳过前几行