Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.80 KB | None | 0 0
  1. first_hash = Hash.new
  2. second_hash = Hash.new
  3.  
  4. first = File.open('first.txt', 'r')
  5. second = File.open('second.txt', 'r')
  6.  
  7. first.each do |line|
  8.     line = line.split(/\t/)
  9.     supID = line[0]
  10.     contID = line[1]
  11.     cbsa = line[2]
  12.     ctgy = line[3]
  13.     first_hash["#{contID}|""#{cbsa}|""#{ctgy}"] ||= []
  14.     first_hash["#{contID}|""#{cbsa}|""#{ctgy}"] << "#{supID}"
  15. end
  16.  
  17. first_hash.each do |key, value|
  18.     key = key.split("|")
  19.     contID = key[0]
  20.     cbsa = key[1]
  21.     ctgy = key[2]
  22.     second.each do |line|
  23.         line = line.split(/\t/)
  24.         contID = line[0]
  25.         cbsa = line[1]
  26.         ctgy = line[2]
  27.         mftr = line[3]
  28.         model = line[4].strip
  29.         value.each do |item|
  30.             second_hash["#{contID}|""#{cbsa}|""#{ctgy}|""#{item}"] ||= []
  31.             second_hash["#{contID}|""#{cbsa}|""#{ctgy}|""#{item}"] << "#{model}"
  32.         end
  33.     end
  34. end
  35.  
  36. puts second_hash
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement