icol = {} for line in ARGF row = line.sub(/^"/, '').sub(/"\r?\n$/, '').split(/","/) if icol.empty? row.size.times {|i| icol[row[i]] = i} else c = row[icol['Indicator']] next unless 'RJTD' == c t = row[icol['Identifier']] next unless /^[HY]/ === t names = %w(Discipline Grid Resolution Area Level ReferenceTime Access) vals = names.map{|n| row[icol[n]]} puts [t, c, vals].flatten.join("\t") end end