Sha256: b1238625df0434dee74ee78e26bd68e972a7f915a2c4b6dc459269d6f5e89397

Contents?: true

Size: 443 Bytes

Versions: 1

Compression:

Stored size: 443 Bytes

Contents

#!/usr/bin/env ruby

require 'csv'

csv_paths = ARGV

out = $stdout

headers_per_file = csv_paths.inject({}) do |memo, path|
  memo[path] = CSV.parse_line(File.open(path) { |f| f.gets })
  memo
end

maximal_headers = headers_per_file.values.inject(:+).uniq

headers = maximal_headers

out.puts headers.to_csv
csv_paths.each do |path|
  CSV.foreach(path, headers: true) do |row|
    out.puts row.values_at(*headers).to_csv
  end
end

out.close

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csvstack2-0.0.1 bin/csvstack2