From: Suraj Kurapati Date: 2007-05-04T03:16:37+09:00 Subject: Re: search and replace text in files Phil Swenson wrote: > I need to search a file for text "InstallDir=" + newline character and > replace it with something like: InstallDir=C\:\\mws71 + newline >> "InstallDir=\n".gsub /(InstallDir=)(\n)/, '\1C\:\mws71\2' => "InstallDir=C\\:\\mws71\n" > My own experimentation with this had problems with writing the back- > slashes to the file (it's a requirement of the format to have the back- > slashes as in my example). The string had the back-slashes in it but > they didn't get persisted to the file correctly. In a single-quoted string, one backslash outputs one backslash. In a double-quoted string, two backslashes outputs one backslash. >> '\ ' => "\\ " >> "\\ " => "\\ " > Are there any libraries that perform a search and replace? String#gsub -- Posted via http://www.ruby-forum.com/.