Created
July 18, 2013 11:48
-
-
Save jamesnesfield/6028699 to your computer and use it in GitHub Desktop.
a multi-file hierarchical "find and replace" that plays nice with spaces in names.
This file contains hidden or 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
#!/bin/bash | |
startdirectory="/Users/jamesnesfield/Desktop/replaceTest/" | |
searchterm="foo" | |
replaceterm="bar" | |
i=0 | |
IFS=$'\n'; | |
for file in $( grep -l -R $searchterm $startdirectory) | |
do | |
((i++)) | |
echo $file | |
sed -e "s/$searchterm/$replaceterm/g" "$file" > /tmp/tempfile.tmp | |
mv /tmp/tempfile.tmp $file | |
done | |
echo "done. changed $i files." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment