Sha256: fa7d591cafdc6224477efa115c3ff0fd3caa5bec94096d9e131bf7e86997b605

Contents?: true

Size: 1.41 KB

Versions: 132

Compression:

Stored size: 1.41 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
Slice column from tsv

$ rbbt tsv slice [options] file.tsv -f "Field 1"

Display summary informations. Works with Tokyocabinet HDB and BDB as well.

-tch--tokyocabinet File is a TC HDB
-tcb--tokyocabinet_bd File is a TC BDB
-hh--header_hash* Change the character used to mark the header line (defaults to #)
-f--fields* Field to slice (comma-separated)
-h--help Help
EOF

SOPT.usage if options[:help]

file = ARGV.shift

file = case file
       when "-"
         STDIN
       when String
         Open.open(file)
       else
         raise ParameterException, "Please specify the tsv file as argument" if file.nil?
       end

fields = options[:fields]
raise ParameterException, "Please specify the fields to slice" if fields.nil?

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
  stream = TSV.traverse file, options.merge(:into => :stream, :type => :list, :fields => fields.split(","), :unnamed => true) do |k,fields,names|
    [k,fields].flatten * "\t"
  end
  puts stream.read
  exit 0
end

puts tsv.slice(fields.split(","))

Version data entries

132 entries across 132 versions & 1 rubygems

Version Path
rbbt-util-5.33.17 share/rbbt_commands/tsv/slice
rbbt-util-5.33.16 share/rbbt_commands/tsv/slice
rbbt-util-5.33.15 share/rbbt_commands/tsv/slice
rbbt-util-5.33.14 share/rbbt_commands/tsv/slice
rbbt-util-5.33.13 share/rbbt_commands/tsv/slice
rbbt-util-5.33.12 share/rbbt_commands/tsv/slice
rbbt-util-5.33.11 share/rbbt_commands/tsv/slice
rbbt-util-5.33.9 share/rbbt_commands/tsv/slice
rbbt-util-5.33.8 share/rbbt_commands/tsv/slice
rbbt-util-5.33.7 share/rbbt_commands/tsv/slice
rbbt-util-5.33.6 share/rbbt_commands/tsv/slice
rbbt-util-5.33.5 share/rbbt_commands/tsv/slice
rbbt-util-5.33.4 share/rbbt_commands/tsv/slice
rbbt-util-5.33.3 share/rbbt_commands/tsv/slice
rbbt-util-5.33.2 share/rbbt_commands/tsv/slice
rbbt-util-5.33.1 share/rbbt_commands/tsv/slice
rbbt-util-5.33.0 share/rbbt_commands/tsv/slice
rbbt-util-5.32.30 share/rbbt_commands/tsv/slice
rbbt-util-5.32.28 share/rbbt_commands/tsv/slice
rbbt-util-5.32.27 share/rbbt_commands/tsv/slice