From: Drew Olson Date: 2007-08-09T04:19:07+09:00 Subject: Re: File parsing Matthew Lagace wrote: > Hello, > > I have a tab delimited file, I have no headers in the file, and one > column is the datestamp of the record. Now this datestamp is not in the > correct format, I know how to format the datestamp to the way I want, > but how do I replace the incorrect datestamp in the file with the new > datestamp I have formatted. > > For e.g.: The datestamp in the file is 2007-12-30 12:32:12, > Here is the datestamp that I want to replace it with instead 20071230 > > How do I replace the old datestamp with my new datestamp in a file? > > Thanks Maybe this? File.open("newfile.txt","w") do |out| File.open("curfile.txt","r").each do |line| out << line.gsub(/(\d{4})-(\d{2})-(\d{2}) \d{2}:\d{2}:\d{2}/,'\1\2\3') end end -- Posted via http://www.ruby-forum.com/.