如何使用记事本++查找和替换多个文件中的行?


12

我现在一直在弄弄notepad ++,对如何执行此操作感到困惑:

我在要搜索的多个文件(在根目录中)中有一行。例:

Brittany (File 1)
     PeopleSleptWith 2
Tiffany (File 2)
     PeopleSleptWith 4
Bonqueesh (File 3)
     PeopleSleptWith 3456
.
.
.

我的目标是PeopleSleptWith用一个常量(IE PeopleSleptWith 7)替换所有行,但是当我搜索并替换多个文件时,它不会删除完整的行,从而导致:

Brittany (File 1)
     PeopleSleptWith 7 2
Tiffany (File 2)
     PeopleSleptWith 7 4
Bonqueesh (File 3)
     PeopleSleptWith 7 3456

实际上,我想要:

Brittany (File 1)
     PeopleSleptWith 7
Tiffany (File 2)
     PeopleSleptWith 7
Bonqueesh (File 3)
     PeopleSleptWith 7

那么,如何继续查找字符串,删除该行中的所有内容,然后将其替换为另一个字符串?

Answers:


21

使用记事本++在文件中的一行上查找字符串,然后用匹配的另一行替换整个行

使用说明

打开记事本++,然后按 Ctrl+ F,然后从Find in Files选项卡选项中。

现在你会...

  1. 将字符串放入“ 查找内容”的正则表达式格式中: ^.*(PeopleSleptWith).*$

    • 字符串将在()括号之间,如上图所示。#1
  2. 放置5个空格,然后放置替换为: PeopleSleptWith 7字符串

  3. 把过滤器: as *.*或*.txtor替换文件类型为明智的选择
  4. 将目录放在您想要的位置(根文件夹)
  5. 检查Regular expression选项
  6. 选择 Replace in Files
  7. 检查文件,现在都应该正确

    在此处输入图片说明


对于那个很抱歉。一开始我什至没有看到。谢谢!
— Sh3perd
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.