Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 407 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 Offline
      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 Offline
        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

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors