Weird result of replacing content

Hi, there

I'm stuck on replacing patterns in a file.

I have http.log, which is generated from system; and a.txt, which is
manually written; Also, i have a replace function that takes string and
replace a pattern.

code is as follow:

def replace(filename,pattern, line)
  content=Array.new()
  File.open(filename, 'r+') do |file|
    #while repcontent=file.gets()
      content = file.read.gsub(/#{pattern}/, line)
      file.seek(0)
      file.write(content)
    #end
  end

end

replace('logs/http.log',"(0[1-9]|[12][0-9]|3[01])\\/(0[1-9]|1[012])\\/20\\d\\d","dd/mm/yy")

#replace('a.txt',"bb","aa")

The attachments are
the original file http.log and it's replaced file http_rep.log

The replace function works fine for a.txt, but it gives extra line in
http_rep.log

Is there anyone know what's going on here?

the original file a.txt and it's replaced file a_replaced.txt

Attachments:
http://www.ruby-forum.com/attachment/2473/a.txt

···

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

a_rep.txt

Attachments:
http://www.ruby-forum.com/attachment/2474/a_rep.txt

···

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

http.log

Attachments:
http://www.ruby-forum.com/attachment/2475/http.log

···

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

http_rep.log

Attachments:
http://www.ruby-forum.com/attachment/2476/http_rep.log

···

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