Hi Jay,

You Should you move the File.open outside of the 
Zip::ZipFile.foreach....
loop first.

You don't need the while... loop, it is part of the 
text_file.read.split("\n").each loop.
nor the if line.start_with? ....

i.e.
---------------------------------
require 'zip/zip'

cdi_output = File.open("cdiout.txt", "a")  # Open an output file for CDI
cho_output = File.open("choout.txt", "a")  # Open an output file for CHO


# To open the zip file and pass each entry to a block
Zip::ZipFile.foreach(C:\Data\file.zip) do |text_file|
   # Read from entry, turn String into Array, and pass to block
   text_file.read.split("\n").each do |line|
        cdi_output.puts line if /^CDI/ =~ line
        # Print to file if line starts with CDI
        cho_output.puts line if /^CHO/ =~ line
        # Print to file if line starts with CHO
   end
end

cdi_output.close                           # Close cdi_output file
cho_output.close                           # Close cho_output file
--------------------------------

Didin't test it but it should work this way.

Regards,

Eduardo

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