简体   繁体   English

Notepad++ 正则表达式从目录中的文件中删除最后 x 行

[英]Notepad++ Regex Remove Last x Lines From Files In Directory

Have files beginning with 15 lines of needed info, followed by 3280 extra lines of unneeded data.文件以 15 行需要的信息开头,然后是 3280 行多余的不需要的数据。 Have tried multiple regex patterns to remove last 3280 lines in all files in directory.尝试了多种正则表达式模式来删除目录中所有文件中的最后 3280 行。

Tried similar to: ^.*(?:\R.*){3279}\z Fails every time when trying to replace with "" (empty) in directory of files.尝试类似于: ^.*(?:\R.*){3279}\z每次尝试在文件目录中替换为“”(空)时都会失败。

Using Notepad++ Find in Files option.使用 Notepad++ 在文件中查找选项。

How can I remove the last n number of lines from every file in the directory?如何从目录中的每个文件中删除最后 n 行?

You can use您可以使用

Find What : \A(.*(?:\R.*){14})(?s:.*)查找内容\A(.*(?:\R.*){14})(?s:.*)
Replace With : $1替换为: $1

Details :详情

  • \A - start of string ( ^ would do, too, here) \A - 字符串的开始( ^也可以,在这里)
  • (.*(?:\R.*){14}) - fifteen lines (.*(?:\R.*){14}) - 十五行
  • (?s:.*) - any text till end of the file (text). (?s:.*) - 文件末尾的任何文本(文本)。

The replacement is the backreference to Group 1 value.替换是对第 1 组值的反向引用。

Settings:设置:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM