Skip to content

Instantly share code, notes, and snippets.

@TrevorS
Created February 12, 2015 19:04
Show Gist options
  • Save TrevorS/b608f89ee675a1673957 to your computer and use it in GitHub Desktop.
Save TrevorS/b608f89ee675a1673957 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# encoding: utf-8
require 'digest'
source = ARGV[0]
target = ARGV[1]
md5 = Digest::MD5
def parse(source, crypt)
File.open(source, 'rb').map(&:strip).each_with_object({}) do |line, lines|
lines[crypt.digest(line)] = line
end
end
def compare(source, target, crypt)
src = source.dup
tgt = File.open(target, 'rb').map(&:strip).each_with_object({}) do |line, lines|
hash = crypt.digest(line)
src.delete(hash) || lines[hash] = line
end
[src, tgt]
end
src = parse(source, md5)
missing_src, missing_tgt = compare(src, target, md5)
puts "Missing from source: #{source}:"
missing_src.each { |k, v| puts v }
puts "Missing from target: #{target}:"
missing_tgt.each { |k, v| puts v }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment