From: Peter Bailey Date: 2006-04-07T01:03:51+09:00 Subject: Re: Basic input/output question James Gray wrote: > On Apr 6, 2006, at 9:36 AM, Peter Bailey wrote: > >> Hello, >> I spent my $40 on "Programming Ruby," but, it seems dedicated to C >> programmer rocket scientists. I work in publishing and basically I >> just >> need to open files, convert the data, and write the files, either >> to the >> same file or to another. Can someone please help me to write a simple >> structure to read a file "text1.txt", do regexes and stuff in it to >> convert data, and then write the output to "text2.txt." > > Sure, see if something like this would help you: > > File.open("text2.txt", "w") do |output| > File.foreach("text1.txt") do |line| > # change line as need here, for example: > # line.sub!(/regex here/, "replacement here")... > > output << line > end > end > > Hope that helps. > > James Edward Gray II I think that this will help me a lot. Now, I see that this is line oriented. Correct? So, line by line, I can read the lines, change stuff, and write the lines. Cool. Thanks a lot, James! -- Posted via http://www.ruby-forum.com/.