Sha256: d67b5fa7e9dd451688abae5b1338b844e9bcf7045fe8d59c5afbf45240357e25

Contents?: true

Size: 1.67 KB

Versions: 17

Compression:

Stored size: 1.67 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
-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"]

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), options)

  puts "File: #{ file }"
  puts "Type: #{header.type}"
  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
  puts "Rows: #{Log.color :blue, `wc -l #{ file }|cut -f 1 -d' '`}" unless Open.remote? file
  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

17 entries across 17 versions & 1 rubygems

Version Path
rbbt-util-5.13.14 share/rbbt_commands/tsv/info
rbbt-util-5.13.13 share/rbbt_commands/tsv/info
rbbt-util-5.13.12 share/rbbt_commands/tsv/info
rbbt-util-5.13.11 share/rbbt_commands/tsv/info
rbbt-util-5.13.10 share/rbbt_commands/tsv/info
rbbt-util-5.13.9 share/rbbt_commands/tsv/info
rbbt-util-5.13.8 share/rbbt_commands/tsv/info
rbbt-util-5.13.7 share/rbbt_commands/tsv/info
rbbt-util-5.13.6 share/rbbt_commands/tsv/info
rbbt-util-5.13.5 share/rbbt_commands/tsv/info
rbbt-util-5.13.4 share/rbbt_commands/tsv/info
rbbt-util-5.13.3 share/rbbt_commands/tsv/info
rbbt-util-5.13.2 share/rbbt_commands/tsv/info
rbbt-util-5.13.1 share/rbbt_commands/tsv/info
rbbt-util-5.13.0 share/rbbt_commands/tsv/info
rbbt-util-5.12.3 share/rbbt_commands/tsv/info
rbbt-util-5.12.2 share/rbbt_commands/tsv/info