Sha256: eec19b5f3e1f40b34ae3d91a17a0f6ba72fa8befd75b547533012bd6e7777edb

Contents?: true

Size: 1.17 KB

Versions: 80

Compression:

Stored size: 1.17 KB

Contents

#!/usr/bin/env ruby

require 'rbbt-util'
require 'rbbt/util/simpleopt'

options = SOPT.setup <<EOF
Read a TSV file and dump it

$ rbbt tsv keys [options] <filename.tsv|->

Use - to read from STDIN

-k--key_field* Key field
-h--help Print this help
-tch--tokyocabinet File is a tokyocabinet hash database
-tcb--tokyocabinet_bd File is a tokyocabinet B database

EOF
rbbt_usage and exit 0 if options[:help]

file = ARGV.shift

file = STDIN if file == '-'

case
when options[:tokyocabinet]
  tsv = Persist.open_tokyocabinet(file, false)
  tsv.keys.each do |k|
    puts k
  end
  exit
when options[:tokyocabinet_bd]
  tsv = Persist.open_tokyocabinet(file, false, nil, TokyoCabinet::BDB)
  tsv.keys.each do |k|
    puts k
  end
  exit
end

parser = TSV::Parser.new TSV.get_stream(file), options.merge(:fields => [])

options[:merge] = false if options[:merge] == "false"

line = parser.first_line
bar = Log::ProgressBar.new
while line 
  bar.tick

  line = Misc.fixutf8(line)
  line = parser.process line
  raise SKIP_LINE if line.empty?
  parts = parser.chop_line line
  key, values = parser.get_values parts
  values = parser.cast_values values if parser.cast?

  puts key
  line = parser.stream.gets
end

Version data entries

80 entries across 80 versions & 1 rubygems

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