-
-
Save wteuber/83e72ef93a3a88e1f1ada5ddec647953 to your computer and use it in GitHub Desktop.
Compare 2 yaml's in ruby (print matching keys)
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
require 'yaml' | |
def compare_yaml_hash(cf1, cf2, context = []) | |
cf1.each do |key, value| | |
if cf2.key?(key) | |
puts "Contains key : #{key} in path #{context.join(".")}" | |
end | |
value2 = cf2[key] | |
next unless value2 | |
if value.is_a?(Hash) | |
compare_yaml_hash(value, value2, (context + [key])) | |
next | |
end | |
end | |
end | |
f1 = ARGV[0] | |
f2 = ARGV[1] | |
compare_yaml_hash(YAML.load_file(f1), YAML.load_file(f2)) | |
# Based on code posted on http://stackoverflow.com/questions/6274126/how-to-compare-keys-in-yaml-files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment