From: nobu.nokada@... Date: 2002-06-02T17:42:40+09:00 Subject: Re: Problem: Newbie with a question on file arrays and file insertion ... Hi, At Sun, 2 Jun 2002 17:09:07 +0900, Stefan Schmiedl wrote: > > 2)- Say I have text files FileA and FileB. FileA contains a > > text tag in the somewhere in it called, say, > > "". How can I: > > > > - locate the tag in FileA and > > - replace with the entire contents of FileB. > > > > In short, I want to insert FileB in FileA where the tag is, > > then delete the tag. > > if the files are not too large, you could read them as a whole > and then just do string substitution. > > a = File("a").read > b = File("b").read > > a.gsub(//, b) If "a" is large: require 'tempfile' require 'ftools' t = Tempfile.new("foobar") b = nil IO.foreach("a") do |line| t.print(line.gsub(//) do b ||= File.open("b") {|b| b.read} end) end File.copy(t.path, "a") > Be warned: this is written on a sunday morning before breakfast :-) Too, except that it's an evening here. :-) -- Nobu Nakada