Skip to content

Instantly share code, notes, and snippets.

@dspp779
Last active September 26, 2016 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dspp779/7a8585e767ec29731025c67ba0ef2c11 to your computer and use it in GitHub Desktop.
Save dspp779/7a8585e767ec29731025c67ba0ef2c11 to your computer and use it in GitHub Desktop.
require 'csv'
require 'yaml'
def read_tsv(filepath)
table = CSV.read(filepath, col_sep: "\t", headers: true)
table.map(&:to_h)
end
if ARGV.size == 2
data = read_tsv ARGV[0]
File.open(ARGV[1], 'w') { |file| file.write data.to_yaml }
else
STDERR.puts 'usage: ruby tsv_to_yml.rb path/to/tsv path/to/yml'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment