Community
    • Login

    How to delete lines 2, 3, 4, 5 in multiple txt files at once?

    Scheduled Pinned Locked Moved General Discussion
    2 Posts 2 Posters 241 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Chris ballC
      Chris ball
      last edited by

      How to delete lines 2 to 5 in multiple txt files?

      I’ve tried pressing ctrl+shift+F and finding certain perameters, with regEx checked, but I cannot figure out what to search for to delete lines 2, 3, 4, 5.

      Ideas?

      1 Reply Last reply Reply Quote 0
      • Terry RT
        Terry R
        last edited by

        @Chris-ball said in How to delete lines 2, 3, 4, 5 in multiple txt files at once?:

        How to delete lines 2 to 5 in multiple txt files?

        If you are replacing in files which aren’t opened in Notepad++ then this should work for you, it did in a small test for me.

        Using the “Find in Files” option we have
        Find What:(?-s)\A(.+\R)(.+\R){4}
        Replace With:\1

        You would need to set the filters and directory to correspond with the file types and location you are working on.

        Just so you have understanding of what this regex is doing:
        (?-s) means the DOT character does NOT include line feed/carriage returns
        \A this means “start of file”. I tested my regex first as this \A can cause issues, in this case it did not appear to.
        (.+\R) select as many characters as possible (the (?-s) prevents it from spreading past the line ending) and include the line ending (\R). This is capture group #1
        (.+\R){4} same as last portion except the {4} means 4 more the same. This then selects lines 2-5
        \1 means return the first capture group back to the file, so this is line 1

        Terry

        1 Reply Last reply Reply Quote 1
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors