Home > Software engineering >  Notepad Regex Remove Last x Lines From Files In Directory
Notepad Regex Remove Last x Lines From Files In Directory

Time:01-18

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?

CodePudding user response:

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:

enter image description here

  •  Tags:  
  • Related