Created
April 26, 2012 21:26
-
-
Save fabioyamate/2503353 to your computer and use it in GitHub Desktop.
Replacing string in with sed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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