[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Search and Replace over multiple files

Trans

4/22/2006 4:56:00 PM

Just an FYI, this little one-line can come it quite handy:

ruby -pi -w -e 'gsub!(/search/, "replace")' *.rb

Use it to seach through your ruby script files doing a global search
and replace. Be careful though. Make a mistake using it and you'll be
wanting a backup!

T.

2 Answers

Andrew Johnson

4/22/2006 5:29:00 PM

0

On 22 Apr 2006 09:56:15 -0700, Trans <transfire@gmail.com> wrote:
> Just an FYI, this little one-line can come it quite handy:
>
> ruby -pi -w -e 'gsub!(/search/, "replace")' *.rb
>
> Use it to seach through your ruby script files doing a global search
> and replace. Be careful though. Make a mistake using it and you'll be
> wanting a backup!

Hence, specifying a backup extension is a good idea:

ruby -wpi.bak -e '...' xfiles

Now xfiles will first be backed up as xfiles.bak

andrew

William James

4/22/2006 8:43:00 PM

0

Trans wrote:
> Just an FYI, this little one-line can come it quite handy:
>
> ruby -pi -w -e 'gsub!(/search/, "replace")' *.rb
>
> Use it to seach through your ruby script files doing a global search
> and replace. Be careful though. Make a mistake using it and you'll be
> wanting a backup!
>
> T.

Bangless, with backup:

ruby -i.bak -pe 'gsub(/search/, "replace")' *.rb