Sha256: 47b47763a40f6fd664019efc16741a6c4bf668b888199b09d172bf554943b426
Contents?: true
Size: 1.33 KB
Versions: 51
Compression:
Stored size: 1.33 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 Select entries in a tsv based on some criteria $ rbbt tsv subset [options] file.tsv <key> <criteria> 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) -m--merge Merge TSV rows -h--help Help EOF SOPT.usage if options[:help] file, key, criteria = ARGV key, criteria, file = [file, key, nil] if criteria.nil? file = STDIN if file == '-' || file.nil? raise ParameterException, "Please specify the tsv file as argument" if file.nil? 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 criteria = criteria.to_regexp.to_regexp if criteria =~ /\/.*\/.*/ puts tsv.select(key => criteria)
Version data entries
51 entries across 51 versions & 1 rubygems