Sha256: 15d401e5269ee4c24939e3aab1c6e7a3e07930f587e68878cc11cb7935c5aa0e

Contents?: true

Size: 823 Bytes

Versions: 55

Compression:

Stored size: 823 Bytes

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

Description

$ rbbt tsv attach <file1> <file2> [<file3> ...] [options]

Use - to read from STDIN

-f--fields* Fields to attach (all if not specified)
-h--help Print this help

EOF
if options[:help]
  if defined? rbbt_usage
    rbbt_usage 
  else
    puts SOPT.usage
  end
  exit 0
end

file1, *rest = ARGV
fields = options[:fields]

fields = fields ? fields.split(/[,|]/).collect{|f| f.strip} : nil

tsv = TSV.open(file1)

rest.each do |file2|
  file_fields = TSV.parse_header(file2).all_fields - tsv.all_fields
  these_fields = fields ? fields & file_fields : nil
  tsv = tsv.attach file2, :fields => these_fields
end

puts tsv.to_s

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
rbbt-util-5.19.7 share/rbbt_commands/tsv/attach
rbbt-util-5.19.6 share/rbbt_commands/tsv/attach
rbbt-util-5.19.5 share/rbbt_commands/tsv/attach
rbbt-util-5.19.4 share/rbbt_commands/tsv/attach
rbbt-util-5.19.3 share/rbbt_commands/tsv/attach
rbbt-util-5.19.2 share/rbbt_commands/tsv/attach
rbbt-util-5.19.1 share/rbbt_commands/tsv/attach
rbbt-util-5.19.0 share/rbbt_commands/tsv/attach
rbbt-util-5.18.1 share/rbbt_commands/tsv/attach
rbbt-util-5.18.0 share/rbbt_commands/tsv/attach
rbbt-util-5.17.89 share/rbbt_commands/tsv/attach
rbbt-util-5.17.88 share/rbbt_commands/tsv/attach
rbbt-util-5.17.87 share/rbbt_commands/tsv/attach
rbbt-util-5.17.86 share/rbbt_commands/tsv/attach
rbbt-util-5.17.85 share/rbbt_commands/tsv/attach
rbbt-util-5.17.84 share/rbbt_commands/tsv/attach
rbbt-util-5.17.83 share/rbbt_commands/tsv/attach
rbbt-util-5.17.82 share/rbbt_commands/tsv/attach
rbbt-util-5.17.81 share/rbbt_commands/tsv/attach
rbbt-util-5.17.80 share/rbbt_commands/tsv/attach