Random Stuff

Replace String, Recursive

With this you can use single quotes and back slashes to find odd characters. For example '99\/99' would find 99/99 - further, it must be in single quote.

Recurse - Use Thus:

sh script.sh 'findthis' 'replacewiththis' '*.txt'
#!/bin/bash
DATE=$(date +"%Y-%m-%d-%H%M")
###############################################################################
# Date function is used thus - $DATE
# Description: replace string yes recurse, use thus: sh script.sh replacethis withthis *.txt
# Displays before and after results and counts
# Created 2019-11-24
# Updated 2019-11-28
###############################################################################
SEARCH=$1
REPLACE=$2
FILENAME=$3
## Recurse and only alter FILENAME named files ** allow something like *.txt or .*.txt to pick up a dotfile
#                         --------             --                      -----    ------
echo '############# TO BE REPLACED ##################'
grep -Pri "${SEARCH}" ./ |egrep "${FILENAME}" |uniq -c
find . -type f -iname "${FILENAME}" -exec sed -i "s/${SEARCH}/${REPLACE}/g" {} +
echo '############# REPLACED ########################'
grep -Pri "${REPLACE}" ./ |egrep "${FILENAME}" |uniq -c