How to delete all lines found in another txt document

  • I have one document called “source.txt” and one called “delete.txt”.
    I would like to delete every line that is in “delete.txt” from “source.txt”.
    That process should be easily repeatable, because I will have to do that many times…

    Thanks a lot for your help!

  • Hello, @cookiexd and All,

    Here is an easy work-around :

    • Open your source.txt file, in Notepad++

    • At the end of source.txt file, add a new line beginning with, at least, three = equal symbols

    • Then, append the contents of the delete.txt file, after the line =====...

    • To end, add an empty line, at the very end of the file ( IMPORTANT )

    • Now, open the Replace dialog

    • SEARCH (?s-i)^((?-s).+\R)(?=.*^====+\R.*^\1)|^=+\R.+


    • Tick the Wrap around option

    • Select the Regular expression search mode

    • Click, once, on the Replace All button

    • Save the modifications of your Source.txt file

    Notes :

    • First, the in-line modifiers (?s-i) forces, by default, the regex engine :

      • To acts in a sensitive case way (?-i)

      • To consider the regex symbol . as standing for any single character, even an EOL one (?s)

    • Now, this search regex contains two alternatives, separated with the alternation symbol | :

      • In the first alternative ^((?-s).+\R)(?=.*^====+\R.*^\1) :

        • The part ((?-s).+\R) matches any non-null range of standard characters, due to the (?-s) modifier, followed with its line-break \R ( so, a complete line ! ) and stores it as group1 due the outer parentheses

        • But… ONLY IF  followed with the same line \1, somewhere, further on, after the separator line ===== ..., due to the look-ahead construction (?=.*^====+\R.*^\1)

      • In the second alternative ^=+\R.+, when all initial lines of Source.txt file are processed :

        • The part ^=+\R matches the complete separator line ===..., with its like-break

        • Then, the part .+ selects all the subsequent characters, even EOL ones, after this separator line, till the very end of file

    • Whatever the alternative selected, the matched contents are simply deleted as the Replace zone is empty

    Best Regards,


Log in to reply