Permalink
Browse files

add tsv2yaml

  • Loading branch information...
1 parent 93458a3 commit 1110c230ca1b9d7d2d362699605ce61d0ec97c95 @brendano committed Jul 20, 2010
Showing with 24 additions and 0 deletions.
  1. +24 −0 tsv2yaml
View
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+$doc = %{
+yaml2tsv
+
+Takes TSV-with-header and outputs as stream of YAML documents.
+This is a decent way to get key-value pretty printing;
+e.g. useful for if there are many columns.
+}
+
+require 'yaml'
+require 'pp'
+
+if STDIN.tty?
+ STDERR.puts $doc.strip
+ exit 1
+end
+
+columns = STDIN.readline.chomp.split("\t")
+STDIN.each do |line|
+ parts = line.chomp.split("\t")
+ h = {}
+ (0...parts.size).each{|i| h[columns[i]] = parts[i]}
+ puts h.to_yaml
+end

0 comments on commit 1110c23

Please sign in to comment.