Skip to content

Instantly share code, notes, and snippets.

@stansidel
Last active December 22, 2015 12:38
Show Gist options
  • Save stansidel/6473420 to your computer and use it in GitHub Desktop.
Save stansidel/6473420 to your computer and use it in GitHub Desktop.
Ruby CSV sample
#!/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