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']] t = row[icol['Identifier']] next unless /^[A-Z]{4}[0-9]*$/ === t puts [t, c].join(",") end end