Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Search and Replace over multiple files

2 views
Skip to first unread message

Trans

unread,
Apr 22, 2006, 12:56:15 PM4/22/06
to
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.

Andrew Johnson

unread,
Apr 22, 2006, 1:29:02 PM4/22/06
to

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

unread,
Apr 22, 2006, 4:43:10 PM4/22/06
to

Bangless, with backup:

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

0 new messages