WARNING!
MAKE BACKUP of current folder before proceeding!
that being said, this search replace script works with the tool sed which required to escape all special characters.
This tool will help with that: https://dwaves.de/tools/escape/
per default it will search the current folder the user is in.
# make backup of current folder mkdir /root/backups tar fcvz /root/backups/backup_of_current_folder.tar.gz . # make new file vim /root/scripts/global-search-replace.sh # with content #!/bin/bash echo "=== global-search-replace.sh v1.0 ===" echo "WARNING! MAKE BACKUP OF ALL FILES BELOW . BEFORE PROCEEDING!" echo "INPUT ONLY SED ESCAPED STRINGS! (https://dwaves.org/tools/escape/)" echo "(hit enter to continue searching for:" echo "FILETYPE: " echo "$1" echo "and replace all:" echo "$2" echo "with:" echo "$3" echo "in all files in all sub-folders of the current dir)" read input THIS=$2 # shall become THAT=$3 find . -type f -iname "$1" -exec sed --debug -i "s/$THIS/$THAT/g" {} \;
make runnable:
chmod +x /root/scripts/*.sh
usage:
/root/scripts/global-search-replace.sh "*.txt" '\ ' ' '
liked this article?
- only together we can create a truly free world
- plz support dwaves to keep it up & running!
- (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
- really really hate advertisement
- contribute: whenever a solution was found, blog about it for others to find!
- talk about, recommend & link to this blog and articles
- thanks to all who contribute!
