Sha256: 8d6b5f4eb02f6ba09936a3a5ddf1b79b4d95e6fdff0aa83e405a32cf81d79ca9

Contents?: true

Size: 1.13 KB

Versions: 464

Compression:

Stored size: 1.13 KB

Contents

#!/usr/bin/env ruby

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

options = SOPT.setup <<EOF

Pulls the values from a tsv colum

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

Use - to read from STDIN

-tch--tokyocabinet File is a tokyocabinet hash database
-tcb--tokyocabinet_bd File is a tokyocabinet B database
-f--field* Limit to a particular field
-k--keys Print also keys
-h--help Print this help
-l--lines Separate in lines

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)
when options[:tokyocabinet_bd]
  tsv = Persist.open_tokyocabinet(file, false, nil, TokyoCabinet::BDB)
else
  if String === file
    file = file.dup
    Path.setup(File.expand_path(file))
  end
  tsv = file
end

field = options[:field]

fields = field.nil? ? nil : [field]

TSV.traverse(tsv, :fields => fields) do |k,v|
  if options[:lines]
    puts (Array === v ? v.flatten*"\n" : v.to_s ) 
  elsif options[:keys]
    puts(k << "\t" << (Array === v ? v.flatten*"\t" : v.to_s ))
  else
    puts (Array === v ? v.flatten*"\t" : v.to_s ) 
  end
end

Version data entries

464 entries across 464 versions & 1 rubygems

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