From: Kev Jackson Date: 2005-10-03T17:58:16+09:00 Subject: Re: ruby gsub! problem > > > >filename.to_s.gsub!(/\n/, '') would replace all newlines in the >filename. That is certainly not what you want. You could do > >string = File.read(filename).gsub(/\n/, '') > >to get the content of the file without newlines > >and > >lines = File.read(filename).gsub(/\n/, '').split(";", -1) > >to get what you want. The snippet from James is for processing each >line of a file after each other and may be a less memory intensive way >to achieve your goal. > >hope to help, > > Here's what I ended up with - love blocks, without them there'd be a lot more resource handling... File.open("sections.sql", "w") do |output| File.open("TBLSECTION.dat","r") do |input| lines=0 # here I was trying to remove the \n input.to_s.gsub!(/\n/, '') # didn't work so moved into munge_fields input.each(";") do |line| munge_fields line munge_data(line, lines+1) p line output << line << "\n" lines+=1 end p "Total Lines in file : " + lines.to_s end end both munge_fields and munge_data do the sub! thing to bring the data back to the format I want, and although I considered splitting to get an array of strings then creating a builder to rebuild my output, for now it works fine with simple regexps Kev