Skip to content

Instantly share code, notes, and snippets.

@holysugar
Created August 8, 2016 05:17
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 holysugar/aaa8f602d9676b8d34f8db48fb093149 to your computer and use it in GitHub Desktop.
Save holysugar/aaa8f602d9676b8d34f8db48fb093149 to your computer and use it in GitHub Desktop.
from ltsv to csv converter
#!/usr/bin/env ruby
require 'csv'
firstline = true
io = $stdout
while line = ARGF.gets
data = line.chomp.split(/\t/).map{|item| item.split(/:/,2) }.to_h
if firstline
headers = data.keys
io.puts headers.to_csv
firstline = false
end
io.puts data.values_at(*headers).to_csv
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment