Community
    • Login

    Replace all multiline text before first appearance of character in multiple files

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 193 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.
    • Trey Hargrove 0T
      Trey Hargrove 0
      last edited by

      I have found several variations on this question, but none that exactly match what I am trying to do. I am relatively new to Notepad++ and not familiar with the language (so please forgive my ignorance).

      I have thousands of text files from which that I need to delete all of the text from the start of the file until the first appearance of a tilde (~) character. The files contain numerous and inconsistent variations on the text that appears before that first ~. Some files may contain 10 lines of random text before the first ~ and others may contain only 3 lines. There is little consistency in what appears in the first n number of lines that I want to delete. This needs to work with Find In Files

      Examples:

      Line 1 Lorem Ipsum
      Line 2 Nonsense to throw away
      Line 3 ~ This is the first tilde that appears in this file. Keep it and whatever comes after it til the end of the file

      Line 1 Stuff to delete
      Line 2 Other stuff to delete
      Line 3 More stuff to delete
      Line 4 Keep deleting
      Line 5 ~ Keep everything on this line including the first character and everything in all subsequent lines

      Thanks in advance.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Trey Hargrove 0
        last edited by Alan Kilborn

        @Trey-Hargrove-0

        Fairly easy, however you’ll need to use Notepad++ 7.9.1 or later (earlier versions will not handle the \A construct correctly) to do this:

        Use Replace in Files.

        find: \A(?s).*?~
        repl: ~

        Suggest making a backup of your whole fileset first; delete only after you’ve decided it works as intended.

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