Created
February 16, 2013 15:36
-
-
Save stanaka/4967403 to your computer and use it in GitHub Desktop.
a converter from LTSV to JSON.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'optparse' | |
require 'json' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: ltsv2json.rb [options]" | |
opts.on("-f", "--format FORMAT", "Select format.") do |v| | |
options[:format] = v | |
end | |
end.parse! | |
while gets | |
record = Hash[$_.split("\t").map{|f| f.split(":", 2)}] | |
case options[:format] | |
when 'ltsv' | |
puts $_ | |
when 'ssv' | |
puts record.values.join(' ') | |
else | |
puts record.to_json | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment