Reputation: 1717
I have two files with email addresses (one per line): file1 and file2.
How can I remove all the emails in file1 which also exist in file2? Looking for a bash answer, but any other scripting language is fine as well.
If it helps, in each file are only unique email addresses.
Upvotes: 0
Views: 56
Reputation: 1
If you must preserve the order for whatever reason and want to be overly complicated by contemplating case sensitiveness and carriage returns (^M) you can try:
perl -e '%e=();while(<>){s/[\r\n]//g;$e{lc($_)}=1}open($so,"<","file1");while(<$so>){s/[\r\n]//g;print "$_\n" if(!exists($e{lc($_)}))}close($so)' file2
Upvotes: 0
Reputation: 56129
join -v1 <(sort file1) <(sort file2)
This tells join
to print the lines (emails) in file1 that do not appear in file2. They have to be sorted, whence the <(sort ...)
.
Upvotes: 1