简体   繁体   中英

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. Have tried multiple regex patterns to remove last 3280 lines in all files in directory.

Tried similar to: ^.*(?:\R.*){3279}\z Fails every time when trying to replace with "" (empty) in directory of files.

Using Notepad++ Find in Files option.

How can I remove the last n number of lines from every file in the directory?

You can use

Find What : \A(.*(?:\R.*){14})(?s:.*)
Replace With : $1

Details :

  • \A - start of string ( ^ would do, too, here)
  • (.*(?:\R.*){14}) - fifteen lines
  • (?s:.*) - any text till end of the file (text).

The replacement is the backreference to Group 1 value.

Settings:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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