leonteale

hashes_unique.rb

Nov 11th, 2013
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.84 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. #
  4. # Hash format: username::domain:1122334455667788:3B5889EBD28E72A95084162766094D23:010100000000000
  5. #
  6.  
  7. hashes     = File.open(ARGV[0]).read
  8. new_hashes = {}
  9.  
  10. hashes.split("\n").each do |hash|
  11.   username = hash.match(/^.+::/)[0].gsub('::','')
  12.   parts    = hash.gsub(username+'::', '').split(':')
  13.  
  14.   new_hashes[username] = {  :part0 => parts[0], :part1 => parts[1], :part2 => parts[2], :part3 => parts[3] }
  15. end
  16.  
  17. new_hashes.each_pair do |key, value|
  18.   part0 = value[:part0].nil? ? '' : value[:part0]
  19.   part1 = value[:part1].nil? ? '' : value[:part1]
  20.   part2 = value[:part2].nil? ? '' : value[:part2]
  21.   part3 = value[:part3].nil? ? '' : value[:part3]
  22.  
  23.   if part3 == ''
  24.     puts key + '::' + part0 + ':' + part1 + ':' + part2
  25.   else
  26.     puts key + '::' + part0 + ':' + part1 + ':' + part2 + ':' + part3
  27.   end
  28. end
  29.  
  30. exit
Advertisement
Add Comment
Please, Sign In to add comment