Skip to content

Instantly share code, notes, and snippets.

/csv.rb Secret

Created April 17, 2014 14:57
Show Gist options
  • Save anonymous/b7b18d54f6b39a755317 to your computer and use it in GitHub Desktop.
Save anonymous/b7b18d54f6b39a755317 to your computer and use it in GitHub Desktop.
require 'fileutils'
require 'csv'
FileUtils.cd('/data/bluekiwi/bkweb/application/config/')
configs = {}
Dir.glob('configuration_*').each do |filename|
configs[filename]= Hash.new
File.foreach(filename) do |line|
if line.include? 'uid'
next unless line.match(/(?=uid).*?[\'\"].*?[\'\"](.*?)[\'\"]/)
field, value = line.split("=",2);
configs[filename][:uid]= value
end
if line.include? 'url'
next unless line.match(/(?=url).*?[\'\"].*?[\'\"](.*?)[\'\"]/)
field, value = line.split("=",2);
configs[filename][:url]= value
end
if line.include? 'dbname'
next unless line.match(/(?=dbname).*?[\'\"].*?[\'\"](.*?)[\'\"]/)
field, value = line.split("=",2);
configs[filename][:dbname]= value
end
CSV.open("/tmp/data.csv", "wb", Options = {col_sep: "\t", quote_char: "\0"}) {|csv| configs.to_a.each {|input| csv << input }}
end
end
configuration_emakina.mydomain.net.php {:uid=>" 'grouperefl';", :url=>" 'https://emakina.mydomaine.net';", :dbname=>"'grouperefl';"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment