Skip to content

Instantly share code, notes, and snippets.

@olivatooo
Created March 8, 2020 22:13
Show Gist options
  • Save olivatooo/aee1fa99a8e6457bbad4f16e51422e49 to your computer and use it in GitHub Desktop.
Save olivatooo/aee1fa99a8e6457bbad4f16e51422e49 to your computer and use it in GitHub Desktop.
Script to find and replace recursively using sed
#!/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