Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fabioyamate
Created April 26, 2012 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabioyamate/2503353 to your computer and use it in GitHub Desktop.
Save fabioyamate/2503353 to your computer and use it in GitHub Desktop.
Replacing string in with sed
# replaces all string matches in files
#
# USAGE:
# sr $from $to
# sr $from $to $type
#
# Arguments:
# $from - from value
# $to - to value
# $type - file type. DEFAULT: *.rb
#
# example:
# sr foo bar
# sr foo bar *.css
function sr()
{
local from=$1
local to=$2
local type=${3-*.rb}
find . -name $type -exec sed -i '' "s/$from/$to/g" {} +
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment