Created
March 8, 2020 22:13
-
-
Save olivatooo/aee1fa99a8e6457bbad4f16e51422e49 to your computer and use it in GitHub Desktop.
Script to find and replace recursively using sed
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 | |
# find_and_replace.sh | |
echo "Find and replace in current directory!" | |
echo "File pattern to look for? (eg '*.txt')" | |
read filepattern | |
echo "Existing string?" | |
read existing | |
echo "Replacement string?" | |
read replacement | |
echo "Replacing all occurences of $existing with $replacement in files matching $filepattern" | |
find . -type f -name $filepattern -print0 | xargs -0 sed -i '' -e "s/$existing/$replacement/g" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment