Sublime Forum

Subtract one file from another

#1

Hello everybody, I’m quite new to ST.

I have to delete lines (mail addresses) from one file from another file. The FileDiff Package can make the differences visible, but cannot subtract one file from onother.

Any idea to do this?

Thanks in advance!

0 Likes

#2

The following technique assumes you have two files, each of which has one email address per line. It also assumes neither list has any duplicates.

Firstly, take the list of email addresses to be deleted, and append it to the bottom of the list of all email addresses. Now sort the file (via Edit/Sort Lines). You should have one file, with all the emails that need to be deleted having two entries next to each other.

You can find all repeated lines using this regex:

(.*)\n(\1)\n

Open the Find panel, turn on the Regex flag (the .* button), then press Find All: all duplicated lines should now be selected, and you can simply delete them.

0 Likes

#3

Nice trick to delete duplicate lines :smile:

0 Likes

#4

That’s not subtraction. With two files, A and B, and you want to do A - B, this will keep lines from B that should not be there. This operation you describe is the symmetric difference of sets.

Example:

A:
foo@bar

B:
fizz@buzz

You will find that the result has fizz@buzz when it should not.

0 Likes

#5

No, because:

You take a list of emails to be deleted from the diff, you don’t just append both original files together

0 Likes