Sha256: e38b048b09f9bf1350721b1d53265708c4cd67f057fd3e8053f2bf6a88d2932c
Contents?: true
Size: 1.01 KB
Versions: 22
Compression:
Stored size: 1.01 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 Sort a TSV file, mantaining headers $ rbbt tsv sort file.tsv Display summary information. Works with Tokyocabinet HDB and BDB as well. -hh--header_hash* Change the character used to mark the header line (defaults to #) -f--field* Field to sort by (name or number) -h--help Help EOF SOPT.usage if options[:help] file = ARGV.shift file = STDIN if file == '-' or file.nil? field = options[:field] || '2' if field =~ /^\d+$/ field_pos = field.to_i else parser = TSV.parse_header(file, options) field_pos = parser.all_fields.index(field) + 1 saved_line = parser.line end rest = ARGV.inject("-t\"\t\" -g -k#{field_pos}"){|acc,e| acc << " '#{e}'" } file_io = TSV.get_stream(file) stream = Misc.sort_stream(file_io, options[:header_hash] || "#", rest) begin while line = stream.gets puts line end rescue Exception exit -1 end
Version data entries
22 entries across 22 versions & 1 rubygems