Sha256: 1f4de3f4f17cd02ddd21a824eae4a21fe0110bee5e12c6fef4196f0458d48a3a

Contents?: true

Size: 1022 Bytes

Versions: 6

Compression:

Stored size: 1022 Bytes

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
-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 = TSV.open(file)
end

field = options[:field]
tsv = tsv.slice(field) if field

if options[:lines]
  tsv.each{|k,v| puts (Array === v ? v.flatten*"\n" : v.to_s ) }
else
  tsv.each{|k,v| puts (Array === v ? v.flatten*"\t" : v.to_s ) }
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rbbt-util-5.8.6 share/rbbt_commands/tsv/values
rbbt-util-5.8.4 share/rbbt_commands/tsv/values
rbbt-util-5.8.3 share/rbbt_commands/tsv/values
rbbt-util-5.8.2 share/rbbt_commands/tsv/values
rbbt-util-5.8.1 share/rbbt_commands/tsv/values
rbbt-util-5.8.0 share/rbbt_commands/tsv/values