Diff two email lists and find new and missing email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Diff two email lists and find new and missing emails | |
# To use, call file and pass in an original list and updated list | |
# eg. ruby email_list_diff.rb ~/original_list.txt ~/updated_list.txt | |
original_list = File.readlines(ARGV[0]) | |
updated_list = File.readlines(ARGV[1]) | |
def find_unique_emails(list_01, list_02) | |
# given two email lists, find all emails | |
# in list_01 that are not in list_02 | |
unique_emails = [] | |
list_01.each do |email| | |
# Create an array of any matched emails | |
matches = list_02.select { |line| line[/#{email.chomp}/i] } | |
if matches.empty? | |
# if no matches, it's a unique email | |
puts email | |
unique_emails.push(email) | |
end | |
end | |
return unique_emails | |
end | |
puts "Finding new emails ... " | |
new_emails = find_unique_emails(updated_list, original_list) | |
puts "#{new_emails.count} emails added" | |
puts "Finding missing emails ..." | |
removed_emails = find_unique_emails(original_list, updated_list) | |
puts "#{removed_emails.count} emails removed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment