Last active
December 22, 2015 12:38
-
-
Save stansidel/6473420 to your computer and use it in GitHub Desktop.
Ruby CSV sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "csv" | |
require "FileUtils" | |
require 'open-uri' | |
filename = ARGV[0] | |
skip_line = true | |
CSV.foreach(filename, { :col_sep => "\t" }) do |row| | |
if skip_line | |
skip_line = false | |
next | |
end | |
if "0".eql? row[4] | |
next | |
end | |
next if "N".eql? row[1] | |
new_file_name = URI::encode(row[0].gsub(" ", "_")) | |
FileUtils.mkdir_p("./test/#{row[5]}") | |
file = File.new("./test/#{row[5]}/#{new_file_name}.txt", 'w') | |
file.puts(row[2]) | |
file.close | |
puts "Wrote file #{row[5]}/#{new_file_name}.txt" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment