Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 38 lines (30 sloc) 0.754 kB
#!/usr/bin/env ruby
$doc = %{
yaml2tsv
Takes a YAML document stream -- that is, a concatenation of YAML top-level
objects -- and treats them as key/value records to be turned into
tsv-with-header.
}
require 'yaml'
require 'pp'
if STDIN.tty?
STDERR.puts $doc.strip
exit 1
end
all = []
YAML.load_documents(STDIN) do |ydoc|
all << ydoc
end
cols = all.map{|x| x.keys}.flatten.uniq.sort
puts cols.map{|c| c.gsub(/\s/," ")}.join("\t")
all.each do |ydoc|
puts cols.map{|c| (ydoc[c] || "").to_s.gsub(/\s/," ")}.join("\t")
end
# cols = nil
# YAML.load_documents(STDIN) do |ydoc|
# if cols.nil?
# cols = ydoc.keys.sort
# puts cols.map{|c| c.gsub(/\s/," ")}.join("\t")
# end
# puts cols.map{|c| ydoc[c].gsub(/\s/," ")}.join("\t")
# end
Jump to Line
Something went wrong with that request. Please try again.