sharath
5/22/2006 7:26:00 PM
Hi All,
I'm trying to search for a given string and replacing that string in
all the files wherever it finds. Please find the program as below:
**************************(SearchReplace.rb)***********************
reg_exp =
Regexp.new('(<object[^\r\n>]*>|<applet[^\r\n>]*>)',Regexp::IGNORECASE)
out_file_nm = "output.txt"
out_file = File.new(out_file_nm, "w")
Dir['**/*.jsp'].each do |path|
puts path
File.open(path,"r+" ) do |f|
f.grep(reg_exp) do |line|
puts path, ':', line
out_file.write path +"\n"
f.write line.sub(reg_exp) {|s| 'show(\''+s+'\')' }
end
f.close
end
end
out_file.close
**********************************************************
This program finding the string correctly but it is not replacing
the string. Please let me know how to replace the line after it finds
the string???
Thanks,
Sharath.