def strtime str case str when /^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)Z$/ Time.gm(*($~[1..6].map{|s| s.to_i})) else raise "malformatted time #{str}" end end colh = {} table = [] bt = nil for line in ARGF case line when /^IS_013:/ bt = strtime(line.split(/\s+/)[2]) when /^PDS001:/ table.push Hash.new when /^(PDS(?:001|019|035|042|059|062|067|071|074)|BMS(?:001|006)):/ key = $1 v = line.split(/\s+/)[2] v = (strtime(v) - bt) / 3600.0 if /PDS035/ === line table.last[key] = v colh[key] = true end end cols = colh.keys.sort_by{|k| k.sub(/^PDS/, '4.').sub(/^BMS/, '6.') } puts cols.join("\t") for row in table puts cols.map{|c| row[c]}.join("\t") end