Community
    • Login

    How to compare 2 text files and delete duplicates

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 42 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.
    • JAKJ
      JAK
      last edited by

      How to compare 2 text files and delete duplicates

      would compare + perform this

      Thanks

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @JAK
        last edited by PeterJones

        @JAK ,

        ComparePlus is great for doing a “diff”, where it shows the difference. But it’s not really for quickly/easily deleting extras

        It depends on exactly what you have, but there are some simple ways to delete things from one file that are found in another:

        If you have
        file1:

        apple
        banana
        carrot
        daikon
        eggplant
        fig
        grape
        

        file2:

        apple
        carrot
        jalapeno
        

        If you copy all the contents of file2 and paste them before a --- at the beginning of file1, like:

        apple
        carrot
        jalapeno
        ---
        apple
        banana
        carrot
        daikon
        eggplant
        fig
        grape
        

        Then File > Line Operations > Remove Duplicate Linees will remove the second (or more) occurrence of any line. So the second apple and carrot lines, leaving

        apple
        carrot
        jalapeno
        ---
        banana
        daikon
        eggplant
        fig
        grape
        

        then delete everything before and including the --- line, and your file will now have every line that was in file2 removed from file1. (It will also delete duplicates inside file1, so if file1 had started with an extra fig after the grape, only the first fig would remain.)

        If that doesn’t do what you want, you will have to give more details about your rules.

        Also, if you want an easy way to delete everything before and including the --- line, use FIND WHAT = (?s)\A.*^---\R, REPLACE = empty, Wrap Around = Checkmarked, Search Mode = Regular Expression, Replace All

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