Sha256: 5ced6331d26ecfbfa58cc63bd2c570c9aad3b98ff55b1d81108c2e8146db15e0

Contents?: true

Size: 827 Bytes

Versions: 21

Compression:

Stored size: 827 Bytes

Contents

#!/usr/bin/env ruby

require "find"
require "team_effort"

def do_cmd(cmd)
  system cmd
  status = $?
  raise "'#{cmd}' failed with #{status}" if !status.success?
end

files_dir_path = ARGV[0]
output_file = ARGV[1]
files = Find.find(files_dir_path).reject { |p| FileTest.directory?(p) || File.basename(p) == "log" }

# 1. capture the header from the first file
do_cmd "ghead -n 1 #{files.first} > header"

# 2. strip the header from all files
TeamEffort.work(files) do |file_path|
  file = File.basename(file_path)
  do_cmd "gtail -n +2 #{file_path} > #{file}"
end

# 3. concate the header and all files
tmp_files = files.map{|f| File.basename(f)}
(["header"] + tmp_files).each_slice(20) do |files_to_concat|
  file_list = files_to_concat.join(' ')
  do_cmd "gcat #{file_list} >> #{output_file}"
  do_cmd "rm #{file_list}"
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
advance-0.3.10 bin/concat_csv.rb
advance-0.3.9 bin/concat_csv.rb
advance-0.3.8 bin/concat_csv.rb
advance-0.3.7 bin/concat_csv.rb
advance-0.3.4 bin/concat_csv.rb
advance-0.3.3 bin/concat_csv.rb
advance-0.3.2 bin/concat_csv.rb
advance-0.3.1 bin/concat_csv.rb
advance-0.3.0 bin/concat_csv.rb
advance-0.2.1 bin/concat_csv.rb
advance-0.2.0 bin/concat_csv.rb
advance-0.1.13 bin/concat_csv.rb
advance-0.1.12 bin/concat_csv.rb
advance-0.1.9 bin/concat_csv.rb
advance-0.1.8 bin/concat_csv.rb
advance-0.1.7 bin/concat_csv.rb
advance-0.1.6 bin/concat_csv.rb
advance-0.1.5 bin/concat_csv.rb
advance-0.1.4 bin/concat_csv.rb
advance-0.1.3 bin/concat_csv.rb