Skip to content

Instantly share code, notes, and snippets.

@ebot
Created December 20, 2011 17:39
Show Gist options
  • Save ebot/1502439 to your computer and use it in GitHub Desktop.
Save ebot/1502439 to your computer and use it in GitHub Desktop.
Ruby script that reads the Extraction/Export error logs to generate recovery csv files.
encounters = []
Dir.glob( '*.txt' ).each do |log|
puts "Reading #{log}"
input = File.new log, 'r'
input.each_line do |line|
if line.include? '):'
encounter = line.split( '):' )[0].split( ' - ' )[1]
encounters << encounter unless encounters.include? encounter
end
end
input.close
end
puts "\nGenerating CSV Files..."
file_count = 1
lines_read = 0
master = File.new "recover_all.csv", 'w'
output = File.new "recover_#{file_count}.csv", 'w'
output << "EncounterNo\n"
master << "EncounterNo\n"
encounters.each do |encounter|
output << "#{encounter}\n"
master << "#{encounter}\n"
lines_read += 1
if lines_read > 2500
output.close
file_count += 1
lines_read = 0
output = File.new "recover_#{file_count}.csv", 'w'
output << "EncounterNo\n"
end
end
master.close
output.close
puts "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment