remove email addresses from one file from another

115 views
Skip to first unread message

Christophe Ribot

unread,
Aug 5, 2024, 9:27:51 AM8/5/24
to BBEdit Talk
Hello everyone,

I have two text files composed of email addresses. I want to remove from the first file the emails contained in the second. Is this possible in a simple way with BBEdit?

Thanks for your insights.

Kaveh Bazargan

unread,
Aug 5, 2024, 9:33:22 AM8/5/24
to bbe...@googlegroups.com
If it is a clean list with no leading or trailing spaces, and only one occurrence of an email in each list, then
  • Copy file 2 and add to end of file 1
  • Process duplicate lines – options should show the choices.
If any more complications you need to do a bit more...

--
This is the BBEdit Talk public discussion group. If you have a feature request or believe that the application isn't working correctly, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Mastodon: <https://mastodon.social/@bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/5f9cea39-33b6-43cc-8bd6-b5cb71dd3c8en%40googlegroups.com.


--
Kaveh Bazargan PhD
Director
Accelerating the Communication of Research
  https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/

Kaveh Bazargan

unread,
Aug 5, 2024, 9:37:28 AM8/5/24
to bbe...@googlegroups.com
Sorry, sent too soon. You are trying to remove from the first list any emails also in second. So
    • Copy file 2 and add to end of file 1
    • Sort lines so duplicates are together.
    • Use regex.
      • Search for ^(.+)\r\1\r (start of line, string, end of line, return, same line, return
      • Replace with nothing.
    Hope that works.

    Christophe Ribot

    unread,
    Aug 5, 2024, 10:30:36 AM8/5/24
    to bbe...@googlegroups.com
    Thank you.

    With this solution I end up with addresses in the starting list that should not be there. In fact no address from file 2 should be in the result file.

    An example of what I am trying to do:

    List 1: registered
    ------------------
    don...@disney.com
    ri...@disney.com
    fi...@disney.com
    lou...@disney.com
    mic...@disney.com
    min...@disney.com
    di...@disney.com
    tig...@disney.com
    jas...@disney.com
    pocah...@disney.com

    List 2: unsubscribed (to be removed)
    ---------------------------------

    cru...@disney.com
    ri...@disney.com
    fi...@disney.com
    lou...@disney.com

    Expected result

    You received this message because you are subscribed to a topic in the Google Groups "BBEdit Talk" group.
    To unsubscribe from this topic, visit https://groups.google.com/d/topic/bbedit/g5Zx1xOtvQI/unsubscribe.
    To unsubscribe from this group and all its topics, send an email to bbedit+un...@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/CAJ2R9pgPh6iX08CjRmZrO7xjvSTXfP%3DS-U6xD9%2BbehtS6bUwQA%40mail.gmail.com.


    --
    Christophe Magick! Ribot
    T : 06 35 40 05 37

    Kevin Shay

    unread,
    Aug 5, 2024, 10:35:38 AM8/5/24
    to bbe...@googlegroups.com
    You should be able to use BBEdit's "Process Duplicate Lines..." feature for this.

    1) Paste both lists into a single document as Kaveh suggested.
    2) Text menu > "Process Duplicate Lines..."
    3) Select the "Matching all" radio button and the "Unique lines to new document" checkbox.

    The new document should contain your desired list.

    Cheers,
    Kevin

    flet...@cumuli.com

    unread,
    Aug 5, 2024, 10:39:21 AM8/5/24
    to bbe...@googlegroups.com
    Canonize... on the Text menu can do this. One file contains a series of search/replace commands with the search command first, tab, and then the replacements. This file can be run against other files to perform those replacements.

    Set up list 2 in a file "remove.txt" and append "\t -" to the end of each line. This will replace each email address with the dummy character -.


    Now, open list 1 and run Canonize... on the Edit menu choosing your "remove.txt" file. The result looks like this and then you can remove the stray - lines using search/replace or by sorting them.


    I used a dummy character - because BBEdit was removing white space from the end of my lines which I'm sure is a preference somewhere.

    [fletcher]


    Kaveh Bazargan

    unread,
    Aug 5, 2024, 10:45:02 AM8/5/24
    to bbe...@googlegroups.com
    Looks like my solution was not correct, and you have two good solutions. I did not know about Canonize. 

    Just for the record I just did this:
    • Copy file 2 and temporarily paste into file 1
    • Process duplicate lines and Copy duplicates to clipboard.
    • Open original file 1
    • Paste
    • Sort
    • Use the regex mentioned before
    Hopefully one of above solutions work. :-)

    Regards
    Kaveh


    Christophe Ribot

    unread,
    Aug 5, 2024, 10:54:42 AM8/5/24
    to bbe...@googlegroups.com
    With this solution I end up with the address cru...@disney.com in the result file.

    Christophe Ribot

    unread,
    Aug 5, 2024, 10:55:47 AM8/5/24
    to bbe...@googlegroups.com
    Thanks Fletcher, I'll give this a try.

    Kaveh Bazargan

    unread,
    Aug 5, 2024, 11:01:08 AM8/5/24
    to bbe...@googlegroups.com

    Kevin Shay

    unread,
    Aug 5, 2024, 11:05:05 AM8/5/24
    to bbe...@googlegroups.com
    Ah, I see. In that case you can do it in two passes: paste the output of my steps 1-3 back into List 1, then do Process Duplicate Lines again, this time with "Leaving one" and "Duplicates to new document."

    Massimo Rainato

    unread,
    Aug 5, 2024, 11:56:41 AM8/5/24
    to bbe...@googlegroups.com
    Not linear but: paste twice file 2 unsubscribe list so youi guarantee leave from duplicate also when are not in subscribed list. Easy 

    Christophe Ribot

    unread,
    Aug 6, 2024, 3:02:45 AM8/6/24
    to BBEdit Talk
    Thank you very much for this quick and easy solution, it's perfect for me!
    Best regards
    Reply all
    Reply to author
    Forward
    Message has been deleted
    0 new messages