Replace UUID's (in OpenCms or Magnolia)

In content management systems like OpenCms or Magnolia you often run into the problem of having to replace UUID's.
I wrote a little BASH-script for that.

#!/bin/bash
# example:
# ./replaceUUIDS.sh config.xml
# you can also use wildcards in the filename
#
# marc@johnen.biz
# http://www.johnen.biz

FILE_NAME=$1

echo Finding all existing uuids
OLDIFS=$IFS #make bash interpret escape sequences -> backslash n as a linebreak
IFS=$'\n'
UUIDS=$(find -type f -iname "$FILE_NAME" -print0| xargs -0 grep -hoER "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}" | sort -u)
# for grep: h=supress output of filename, o=only show matching part E=use regex, R=only search file which match pattern, r=recursive search
# find all files matching FILE_NAME
IFS=$OLDIFS

echo Generating SED-Strings
#generating a SED-string for each UUID which will run in the loop for each file
b=0;
for i in $UUIDS;

do
  b=$(( $b + 1 ))
  NEW_UUID=$(uuidgen);
  NEW_PART=`echo "'s/$i/${NEW_UUID}/g'" | sed -e 's/-/\\\-/g'` #this replacement of - with \- may not be necessary
  echo $b = $NEW_PART;
  SED_STRING="${SED_STRING}-e${NEW_PART} ";
done

echo Finding files with UUIDS and replace them
#exchange all uuids with new ones
FILES=$(find . -type f -name "$FILE_NAME")
for f in ${FILES[@]};
do
  eval sed $SED_STRING -i $f
  echo Replacing UUIDS in file $f;
done

#exit;