Search and Replace over multiple files

Discussion in 'Ruby' started by Trans, Apr 22, 2006.

  1. Trans

    Trans Guest

    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.
     
    Trans, Apr 22, 2006
    #1
    1. Advertising

  2. On 22 Apr 2006 09:56:15 -0700, 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!


    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
     
    Andrew Johnson, Apr 22, 2006
    #2
    1. Advertising

  3. 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
     
    William James, Apr 22, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    959
    M.E.Farmer
    Feb 13, 2005
  2. utab
    Replies:
    3
    Views:
    856
  3. karthikbalaguru
    Replies:
    3
    Views:
    3,042
    Chris Dollin
    Nov 27, 2008
  4. RajaniKumarV
    Replies:
    0
    Views:
    462
    RajaniKumarV
    Feb 22, 2010
  5. Roger Johansson

    Search-replace in multiple files?

    Roger Johansson, Oct 9, 2003, in forum: Perl Misc
    Replies:
    5
    Views:
    163
    Bob Walton
    Oct 10, 2003
Loading...

Share This Page