Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
weird result of replacing content
Cheyne Li
8/1/2008 9:04:00 PM
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-...
attachment/...
--
Posted via
http://www.ruby-...
.
3 Answers
Cheyne Li
8/1/2008 9:05:00 PM
0
a_rep.txt
Attachments:
http://www.ruby-...
attachment/2474...
--
Posted via
http://www.ruby-...
.
Cheyne Li
8/1/2008 9:08:00 PM
0
http.log
Attachments:
http://www.ruby-...
attachment/247...
--
Posted via
http://www.ruby-...
.
Cheyne Li
8/1/2008 9:08:00 PM
0
http_rep.log
Attachments:
http://www.ruby-...
attachment/2476/ht...
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
weird result of replacing content
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password