Skip to content
recursive_replace is a ruby gem for recursively replacing text in multiple files and directories. It also escapes special characters, so you can replace code syntax and special characters easily.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
lib
spec
test
.document
.gitignore
Gemfile
LICENSE.txt
README.md
Rakefile
VERSION
recursive_replace.gemspec

README.md

recursive_replace

  • A ruby gem for recursively replacing text in multiple files and directories.
  • Use with shell executable or in code.
  • It auto-escapes most characters, so you can replace code syntax and special characters easily without using regular expressions.
  • Comes with a rspec testing suite for replacement verification of special characters, expressions and code syntax.

Installation

gem install recursive_replace

Examples

From Console/Terminal

recursive_replace [original] [replacement] [optional_path] 

Replace foo with bar in current directory and its subdirectories:

recursive_replace "foo" "bar"

Replace foo with bar in a specific file:

recursive_replace "foo" "bar" file

Replace erb syntax:

recursive_replace "<%= @object[:foo] %>" "<%= @new_object[:bar] %>" 

Replacing a backslash is the only time you'll actually need to escape an input character.

recursive_replace "\\" "_" somedirectory/ 

From Code

require "recursive_replace"
file = File.join("home", "bob", "Documents")
RecursiveReplace.replace("bad", "good", :path => file)

Testing

Want to add a test to see how recursive_replace performs with a specific situation or programming language? Pull the recursive_replace and run its rspec testing suite:

git clone git://github.com/hulihanapplications/recursive_replace.git
cd recursive_replace
rspec spec/
You can’t perform that action at this time.