bin/split_csv.rb in advance-0.4.3 vs bin/split_csv.rb in advance-0.4.4
- old
+ new
@@ -7,15 +7,17 @@
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"
+header_file_name = "#{csv_file_name}_header"
+system "head -n 1 #{csv_file} > #{header_file_name}"
system "tail -n +2 #{csv_file} | split -l #{lines} -a 3 - #{csv_file_name}_"
-files = Dir.entries(".").reject { |f| f =~ %r{^(\.\.?|log)$} }
+files = Dir.entries(".").reject { |f| f.end_with?(header_file_name) || 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 "cat #{header_file_name} #{file} >> #{tmp_file}"
do_cmd "mv #{tmp_file} #{file}"
end
-do_cmd "rm #{csv_file_name}_header"
+do_cmd "rm #{header_file_name}"
+do_cmd "rename 's/^(.*)\.csv_(.*)$/$1_$2.csv/' *csv*"
puts ""
\ No newline at end of file