Sha256: 1d7763a57c9eb0c5ebe660fd6f2fb6fb4e67506c42c89c364b6a0128909a8c13
Contents?: true
Size: 1.34 KB
Versions: 179
Compression:
Stored size: 1.34 KB
Contents
#!/usr/bin/env ruby require 'rbbt-util' require 'rbbt/util/simpleopt' $0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands options = SOPT.setup <<EOF Subset entries in a tsv $ rbbt tsv subset [options] file.tsv --subset key1,key2,key3 Subsets entries from a TSV file from a given list. Works with Tokyocabinet HDB and BDB as well. -tch--tokyocabinet File is a TC HDB -tcb--tokyocabinet_bd File is a TC BDB -hh--header_hash* Change the character used to mark the header line (defaults to #) -s--subset* Subset of keys (Comma-separated or file) -h--help Help EOF SOPT.usage if options[:help] file = ARGV.shift file = STDIN if file == '-' raise ParameterException, "Please specify the tsv file as argument" if file.nil? subset = options[:subset] raise ParameterException, "Please specify a subset of keys" if subset.nil? if File.exists?(subset) subset = Open.read(subset).split("\n") else subset = subset.split(',') end options[:fields] = options[:fields].split(/,\|/) if options[:fields] options[:header_hash] = options["header_hash"] case when options[:tokyocabinet] tsv = Persist.open_tokyocabinet(file, false) puts tsv.summary when options[:tokyocabinet_bd] tsv = Persist.open_tokyocabinet(file, false, nil, TokyoCabinet::BDB) puts tsv.summary else tsv = TSV.open(file, options) end puts tsv.select(subset)
Version data entries
179 entries across 179 versions & 1 rubygems