Sha256: be623f360686b13f49d3d00c9472795447650d5164149b483d81a1cfa888076d

Contents?: true

Size: 1.6 KB

Versions: 538

Compression:

Stored size: 1.6 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
Query a TSV file 

$ rbbt tsv query [options] <file.tsv> <key>

Display summary information for a TSV entry. Works with Tokyocabinet HDB and BDB.

-tch--tokyocabinet File is a TC HDB
-tcb--tokyocabinet_bd File is a TC BDB
-t--type* Type of tsv (single, list, double, flat)
-hh--header_hash* Change the character used to mark the header line (defaults to #)
-k--key_field* Change the key field
-f--field* Change the fields to display
-s--sep* Change the fields separator (default TAB)
-h--help Help
EOF

SOPT.usage if options[:help]

file, key = ARGV

file = STDIN if file == '-'

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"]
options[:sep] = options["sep"]

case
when options[:tokyocabinet]
  tsv = Persist.open_tokyocabinet(file, false)
when options[:tokyocabinet_bd]
  tsv = Persist.open_tokyocabinet(file, false, nil, TokyoCabinet::BDB)
else
  tsv = TSV.open(file, options)
end

values = tsv[key]

head = "#{Log.color :magenta, tsv.key_field}: " << Log.color(:yellow, key)
puts head
puts (["-"] * Log.uncolor(head).length) * ""
values.zip(tsv.fields) do |value,field|
  if Array === value
    values = value.collect{|v| Log.color(:yellow, v)} * ", "
    puts "#{Log.color :magenta, field}: " << values
  else
    puts "#{Log.color :magenta, field}: " << Log.color(:yellow, value)
  end
end

Version data entries

538 entries across 538 versions & 1 rubygems

Version Path
rbbt-util-6.0.3 share/rbbt_commands/tsv/query
rbbt-util-5.44.1 share/rbbt_commands/tsv/query
rbbt-util-5.43.0 share/rbbt_commands/tsv/query
rbbt-util-5.42.0 share/rbbt_commands/tsv/query
rbbt-util-5.41.1 share/rbbt_commands/tsv/query
rbbt-util-5.41.0 share/rbbt_commands/tsv/query
rbbt-util-5.40.5 share/rbbt_commands/tsv/query
rbbt-util-5.40.4 share/rbbt_commands/tsv/query
rbbt-util-5.40.3 share/rbbt_commands/tsv/query
rbbt-util-5.40.0 share/rbbt_commands/tsv/query
rbbt-util-5.39.0 share/rbbt_commands/tsv/query
rbbt-util-5.38.1 share/rbbt_commands/tsv/query
rbbt-util-5.38.0 share/rbbt_commands/tsv/query
rbbt-util-5.37.16 share/rbbt_commands/tsv/query
rbbt-util-5.37.15 share/rbbt_commands/tsv/query
rbbt-util-5.37.14 share/rbbt_commands/tsv/query
rbbt-util-5.37.13 share/rbbt_commands/tsv/query
rbbt-util-5.37.12 share/rbbt_commands/tsv/query
rbbt-util-5.37.11 share/rbbt_commands/tsv/query
rbbt-util-5.37.10 share/rbbt_commands/tsv/query