Advertisement
Guest User

Untitled

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