Created
February 11, 2009 20:15
-
-
Save ebot/62227 to your computer and use it in GitHub Desktop.
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 -wKU | |
puts "Begin Splitting - #{Time.now}" | |
header_line = "medical_record_number;encounter_number;encounter_start_date;patient_name;patient_birth_date;ip_op_indicator;encounter_type;doc_id;document_date;documnet_create_date;document_modify_date;doc_type_name;doc_type_description;page_number;signed;signatures;annotation_files;text_notes;file_path" | |
input = File.new('index.idx', 'r') | |
line_number = 0 | |
line_limit = 930 | |
file_count = 1 | |
threshold = line_limit | |
output = File.new("index-#{file_count}.idx", 'w') | |
output << header_line | |
input.each_line do |line| | |
line_number += 1 | |
document_page_number = line[line.length-10, 10].split("_")[1].split(".")[0].to_i | |
output << line unless line_number == 1 | |
if line_number > threshold && document_page_number == 1 | |
output.close | |
file_count += 1 | |
threshold += line_limit | |
output = File.new("index-#{file_count}.idx", 'w') | |
output << header_line | |
end | |
end | |
output.close unless output.nil? | |
puts " Created #{file_count} files, from #{line_number} lines." | |
puts "Done splitting - #{Time.now}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment