Tuesday, October 16, 2018

Recursively Replace String in Base Folder

#!/bin/bash

if [ $# -lt 2 ]; then
  echo "Usage: $0 < Base folder> <depth>"
  exit $LINENO
fi

baseFolder=$1
depth=$2

cd ${baseFolder}

i=1
searchPath="*"
while [ $i -lt $depth ]; do
for fileToFix in `egrep -l "mykeyword" ${searchPath}`
do
echo "Processing $fileToFix"
echo "
1,$ s/mykeyword/myKeyWord/g
.
w
q" | ed ${fileToFix}
done
   i=$(($i + 1))
   searchPath="*/${searchPath}"
done

No comments:

Post a Comment