gpt4 book ai didi

visual-studio-code - 如何删除 Visual Studio Code 中的重复行?

转载 作者:行者123 更新时间:2023-12-03 04:58:16 30 4
gpt4 key购买 nike

假设您有以下文本:

abc
123
abc
456
789
abc
abc

我想删除所有“abc”行并只保留一行。我不介意排序。结果应该是这样的:

abc
123
456
789

最佳答案

如果行的顺序不重要

按字母顺序对行进行排序(如果尚未排序),然后执行以下步骤:
(基于此相关问题:How do I find and remove duplicate lines from a file using Regular Expressions?)

  1. Control+F

  2. 切换“替换模式”

  3. 切换“使用正则表达式”(带有 .* 符号的图标)

  4. 搜索字段中,输入^(.*)(\n\1)+$

  5. 在“替换为”字段中,输入 $1

  6. 点击the Replace All button (“全部替换”)。

如果行的顺序很重要,因此您无法排序

在这种情况下,要么求助于 VS Code 之外的解决方案(请参阅 here ),或者 - 如果您的文档不是很大并且您不介意发送“全部替换”按钮 - 请按照前面的步骤操作,但在第 4 步和第 5 步,输入以下内容:
(基于Remove specific duplicate lines without sorting)

Caution: Blocks for files with too many lines (1000+); may cause VS Code to crash; may introduce blank lines in some cases.

  • 搜索:((^[^\S$]*?(?=\S)(?:.*)+$)[\S\s] *?)^\2$(?:\n)?

  • 替换为:$1

然后点击“全部替换”按钮重复出现的次数

当您单击按钮时行数停止减少时,您就会知道已经足够了。导航到文档的最后一行以密切关注。

关于visual-studio-code - 如何删除 Visual Studio Code 中的重复行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37992493/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com