#!/usr/bin/ruby require 'gdbm' dbfile = ARGV.shift raise "usage: #$0 dbfile [input ...]" unless dbfile GDBM.open(dbfile) {|db| for line in ARGF cccc, iata, lat, lon, name = line.chomp.split(/\t/) r = Hash[*db[cccc].to_s.split(/\t/).map{|s| s.split(/:/, 2)}.flatten] r['ia2'] = iata unless iata.empty? r['la2'] = lat r['lo2'] = lon r['sn2'] = name STDOUT.write "[#{cccc}]" db[cccc] = r.to_a.sort.map{|kv| kv.join(':')}.join("\t") end puts '.' }