Created
June 3, 2019 14:29
-
-
Save juliantroeps/3db90c0a7a84dd26ff2da233ae3cd8a3 to your computer and use it in GitHub Desktop.
Basic recursively string replacement shell script.
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 | |
| # Usage: 'sh replace.sh old_string new_string' | |
| # Replaces given string in all files and subfolders (recursively). | |
| if [ -n "$1" ]; then | |
| if [ -n "$2" ]; then | |
| echo "Replacing $1 with $2."; | |
| grep -ilr $1 * | xargs -I@ sed -i '' "s/$1/$2/g" @ | |
| echo "Done!"; | |
| else | |
| echo "Second parameter not supplied. Choose a replacement for string $1." | |
| fi | |
| else | |
| echo "First parameter not supplied. Usage: replace.sh old_string newstring" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment