Created
February 12, 2015 19:04
-
-
Save TrevorS/b608f89ee675a1673957 to your computer and use it in GitHub Desktop.
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
#!/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