Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading