def gribkey str str.sub(/^IS_/, '1.').sub(/^IDS/, '0.').sub(/^GDS/, '3.') \ .sub(/^PDS/, '4.').sub(/^DRS/, '5.').sub(/^BMS/, '6.') end table = {} for line in ARGF next unless /^\w+:/ === line k, v = line.split(/\s+/).values_at(0, 2) table[k] = {} unless table[k] table[k][v] = true end puts "= CONSTANT" for key in table.keys.select{|k| table[k].size == 1}.sort_by{|k| gribkey k} puts [key, table[key].keys.first].join("\t") end puts "= VARIABLE" for key in table.keys.select{|k| table[k].size > 1}.sort_by{|k| gribkey k} puts [key, table[key].keys.sort.join("|")].join("\t") end