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