Skip to content

Instantly share code, notes, and snippets.

@ebot
Created March 31, 2011 16:40
Show Gist options
  • Select an option

  • Save ebot/896728 to your computer and use it in GitHub Desktop.

Select an option

Save ebot/896728 to your computer and use it in GitHub Desktop.
Strips out doc id brackets at trims white space on csv files
#!/usr/bin/env ruby -wKU
input = File.new 'generic_doc_labels.csv'
output = File.new 'generic_document_labels.csv', 'w'
line_number = 0
input.each_line do |line|
unless line_number == 0
fields = line.split '","'
fields[0] = fields[0].gsub( /\{|\}/, '' )
line = ''
fields.each { |field| line << "#{field.gsub("\"\n", '').chomp.strip}\",\"" }
end
output << line[0, line.length - 2] << "\n"
line_number += 1
end
input.close
output.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment