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



  • 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.



  • @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.


Log in to reply