Wednesday, April 01, 2009

File renaming SOA & OSB projects

This article is a bit off-topic. But very usefull in SOA and OSB projects. Sometimes you make a typo mistake in your SOA project. In that case you do a rename of file, but what if you find this typo after you completed your service or BPEL process. Then it is an intensive task to change all the filenames and the content of the files. JDeveloper has some refactoring, Eclipse is a bit better into that.

The following script (Linux bash) does a find and replace on a multiple files including the content of those files. Here is the script.

#!/bin/sh

if [ $# -lt 2 ] ; then
echo -e "Wrong number of parameters"
echo -e "Usage:"
echo -e " $0 findstring replacestring filepattern\n."
exit 1
fi

fstring="$1"
rstring="$2"

if [ "$3" = "" ]
then
somefiles="*"
else
somefiles="$3"
fi

echo "find: |${fstring}|"
echo "replace: |${rstring}|"
find . -depth -name "${somefiles}" \! -name ".svn*" -type f -exec sed -i "s/${fstring}/${rstring}/g" {} \;

for FILE in `find . -depth -name "${somefiles}" \! -name ".svn*"`
do
NEW=`echo ${FILE} | sed -e "s/${fstring}/${rstring}/"`
if [ "${NEW}" = "${FILE}" ]
then
:
else
echo $0: mv ${FILE} ${NEW}
mv ${FILE} ${NEW}
fi
done

Post a Comment