Notepad ++删除包含重复单词的行 [英] Notepad++ deleting lines containing duplicate words

查看:82
本文介绍了Notepad ++删除包含重复单词的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.txt文档,该文档由一个单词组成,后跟一行一行的日期,依此类推.

I have a .txt document which consists of one word followed up with a date in one line, and so on in each line.

Notepad ++如何识别不同行中的相同单词并删除重复行?

How can Notepad++ recognize same words in different lines and delete duplicate lines?

推荐答案

假设同一单词的相同出现日期可能不同,并且您希望保留第一个出现在文件中的日期,那么这应该起作用(使确保您的文件以新行结尾):

Assuming the dates can be different for the same occurrence of the same word and you want to keep the one that appears first in the file then this should work (make sure your file end with a new line for this):

  1. 转到替换"对话框(可以执行 Ctrl + F 并转到替换"选项卡).
  2. 在底部的搜索模式"中,选择正则表达式"(确保未选择.匹配换行符").
  3. 在查找内容:"字段中,键入(\ s * \ w +)(.* \ r \ n)((.* \ r \ n)*)\ 1.* \ r \ n
  4. 在替换为:"字段中,键入 \ 1 \ 2 \ 3
  5. 单击替换",直到没有更多的出现为止(全部替换"似乎对此不起作用,并且也许存在一个更好的正则表达式,但它仍适用于该正则表达式,但我没有找到).
  1. Go to the "Replace" dialog (you can do Ctrl+F and go to replace tab).
  2. In the "Search Mode" at the bottom select "Regular expression" (make sure ". matches newline" is not selected).
  3. In the "Find what:" field type (\s*\w+ )(.*\r\n)((.*\r\n)*)\1.*\r\n
  4. In the "Replace with:" field type \1\2\3
  5. Click "Replace" until there are no more occurrences ("Replace All" does not seem to work for this, and perhaps there exists a better regex for which it will work, but I have not found it).

我已经在文件上对此进行了测试:

I've tested this on the file:

testing330     05:09-24/08
whatever     10:55-25/08
testing     15:57-26/08
testing667     19:22-30/08
linux     00:29-31/08
testing330     00:29-31/08
windows     12:25-31/08

结果是:

testing330     05:09-24/08
whatever     10:55-25/08
testing     15:57-26/08
testing667     19:22-30/08
linux     00:29-31/08
windows     12:25-31/08

这篇关于Notepad ++删除包含重复单词的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆