I am really new to Ruby and could use some help with a program. I need
to open a zip file that contains multiple text files that has many rows
of data (eg.)

CDI|3|3|20100515000000|20100515153000|2008|XXXXX4791|0.00|0.00
CDI|3|3|20100515000000|20100515153000|2008|XXXXX5648|0.00|0.00
CHO|3|3|20100515000000|20100515153000|2114|XXXXX3276|0.00|0.00
CHO|3|3|20100515000000|20100515153000|2114|XXXXX4342|0.00|0.00
MITR|3|3|20100515000000|20100515153000|0000|XXXXX7832|0.00|0.00
HR|3|3|20100515000000|20100515153000|1114|XXXXX0238|0.00|0.00

I first need to read through the zip file, read the text files located
in the zip file and write only the complete rows that start with (CDI
and CHO) to two output files, one for the rows of data starting with CDI
and one for the rows of data starting with CHO (basically parsing the
file). I have to do it with Ruby and possibly try to set the program to
an auto function for arrival of continuous zip files of the same
stature. I completely appreciate any advice, direction or help via some
sample anyone can give.

I have been given a little help with reading the text files located in
the zip file with the following.

require 'zip/zip'

# To open the zip file and pass each entry to a block
Zip::ZipFile.foreach(path_to_zip) do |text_file|
   # Read from entry, turn String into Array, and pass to block
   text_file.read.split("\n").each do |line|
      if line.start_with?("CDI") || line.start_with?("CHO")
         # Do something
      end
   end
end

I am hoping to have some help finishing this program with some help
direction or sample as it reads the zip file and sending those rows of
data to my 2 output text files

Thank you in advance for any help with this,
Kind regards, Jay

-- 
Posted via http://www.ruby-forum.com/.