Sha256: 06456f7b89358699801e8e5e73ae6de17ad45e3763b6c77582ebf799f45fdf31

Contents?: true

Size: 1.96 KB

Versions: 73

Compression:

Stored size: 1.96 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
Inspect a TSV file 

$ rbbt tsv info [options] file.tsv

Display summary information. Works with Tokyocabinet HDB and BDB as well.

-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--fields* Change the fields to load
-s--sep* Change the fields separator (default TAB)
-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?

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)
  puts tsv.summary
when options[:tokyocabinet_bd]
  tsv = Persist.open_tokyocabinet(file, false, nil, TokyoCabinet::BDB)
  puts tsv.summary
else
  header = TSV.parse_header(Open.open(file, :nocache => true), options)

  puts "File: #{ file }"
  puts "Type: #{header.type}"
  puts "Namespace: #{header.namespace}"
  puts "Key: #{Log.color :yellow, header.key_field}"
  puts "Fields: "
  if header.fields.nil?
  else
    header.fields.each_with_index do |f,i|
      puts "  - #{Log.color :cyan, i + 1}: " << Log.color(:yellow, f)
    end
  end

  if String === file and not Open.remote? file and File.exist? file
    rows = `wc -l '#{ file }' 2>/dev/null|cut -f 1 -d' '`
  else
    rows = "Could not get rows of #{Misc.fingerprint file}"
  end
    puts "Rows: #{Log.color :blue, rows}" 
    parts = []
    header.first_line.split(header.sep).each_with_index{|p,i| parts << (Log.color(:cyan, "(#{i}) ") << p.strip) }
    puts parts * "\t"
  puts
end

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
rbbt-util-5.21.91 share/rbbt_commands/tsv/info
rbbt-util-5.21.90 share/rbbt_commands/tsv/info
rbbt-util-5.21.89 share/rbbt_commands/tsv/info
rbbt-util-5.21.87 share/rbbt_commands/tsv/info
rbbt-util-5.21.86 share/rbbt_commands/tsv/info
rbbt-util-5.21.85 share/rbbt_commands/tsv/info
rbbt-util-5.21.84 share/rbbt_commands/tsv/info
rbbt-util-5.21.83 share/rbbt_commands/tsv/info
rbbt-util-5.21.81 share/rbbt_commands/tsv/info
rbbt-util-5.21.80 share/rbbt_commands/tsv/info
rbbt-util-5.21.78 share/rbbt_commands/tsv/info
rbbt-util-5.21.77 share/rbbt_commands/tsv/info
rbbt-util-5.21.76 share/rbbt_commands/tsv/info
rbbt-util-5.21.75 share/rbbt_commands/tsv/info
rbbt-util-5.21.74 share/rbbt_commands/tsv/info
rbbt-util-5.21.73 share/rbbt_commands/tsv/info
rbbt-util-5.21.72 share/rbbt_commands/tsv/info
rbbt-util-5.21.71 share/rbbt_commands/tsv/info
rbbt-util-5.21.70 share/rbbt_commands/tsv/info
rbbt-util-5.21.69 share/rbbt_commands/tsv/info