re = /^([[:xdigit:]]{4})([[:xdigit:]]{4})([[:digit:]]{5}) ([[:digit:]]{5}) ([^,]+), (.*) $/ # 1 2 3 4 5 6 # cell id (hex) PLZ city info File.open('26201muenchen.clf', 'r') do |f| puts '# -*- coding: UTF-8 -*-' puts 'class CellInfo:' puts ' x={}' while line = f.gets if not line =~ /^\/\// if match = re.match(line) cell_id = match[1].hex city = match[5] plz = match[4] info = match[6] puts " x[#{cell_id}]='#{plz} #{info}'" end end end end # A little test puts "print CellInfo.x[25867]"