Sha256: 595e34fdfd1cd5d83aa84180b77d26b253a5aa86b2adeae59144b4f86889aadd

Contents?: true

Size: 610 Bytes

Versions: 10

Compression:

Stored size: 610 Bytes

Contents

#!/usr/bin/env ruby
require 'team_effort'

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

csv_file = ARGV[0]
lines = ARGV[1]
csv_file_name = File.basename(csv_file)
system "head -n 1 #{csv_file} > #{csv_file_name}_header"
system "tail -n +2 #{csv_file} | split -l #{lines} -a 3 - #{csv_file_name}_"
files = Dir.entries(".").reject { |f| f =~ %r{^(\.\.?|log)$} }
TeamEffort.work(files, 1) do |file|
  tmp_file = "tmp_#{file}"
  do_cmd "cat #{csv_file_name}_header #{file} >> #{tmp_file}"
  do_cmd "mv #{tmp_file} #{file}"
end
do_cmd "rm #{csv_file_name}_header"
puts ""

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
advance-0.4.3 bin/split_csv.rb
advance-0.4.2 bin/split_csv.rb
advance-0.4.1 bin/split_csv.rb
advance-0.3.18 bin/split_csv.rb
advance-0.3.16 bin/split_csv.rb
advance-0.3.15 bin/split_csv.rb
advance-0.3.14 bin/split_csv.rb
advance-0.3.13 bin/split_csv.rb
advance-0.3.12 bin/split_csv.rb
advance-0.3.11 bin/split_csv.rb