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.37.8 share/rbbt_commands/tsv/values
rbbt-util-5.37.6 share/rbbt_commands/tsv/values
rbbt-util-5.37.4 share/rbbt_commands/tsv/values
rbbt-util-5.37.3 share/rbbt_commands/tsv/values
rbbt-util-5.37.1 share/rbbt_commands/tsv/values
rbbt-util-5.37.0 share/rbbt_commands/tsv/values
rbbt-util-5.36.0 share/rbbt_commands/tsv/values
rbbt-util-5.35.4 share/rbbt_commands/tsv/values
rbbt-util-5.35.3 share/rbbt_commands/tsv/values
rbbt-util-5.35.2 share/rbbt_commands/tsv/values
rbbt-util-5.35.1 share/rbbt_commands/tsv/values
rbbt-util-5.34.27 share/rbbt_commands/tsv/values
rbbt-util-5.34.26 share/rbbt_commands/tsv/values
rbbt-util-5.34.25 share/rbbt_commands/tsv/values
rbbt-util-5.34.24 share/rbbt_commands/tsv/values
rbbt-util-5.34.23 share/rbbt_commands/tsv/values
rbbt-util-5.34.22 share/rbbt_commands/tsv/values
rbbt-util-5.34.21 share/rbbt_commands/tsv/values
rbbt-util-5.34.20 share/rbbt_commands/tsv/values
rbbt-util-5.34.18 share/rbbt_commands/tsv/values