Forum OpenACS Q&A: Re: Res: How to integrate an existing application package with dotLRN

Hello!

For find text, replace text or rename files
recursively on a dir tree we are using the
next scripts (on Linux):

-Script: replaceall ----- Cut here -----------------
#! /bin/sh
# (c) Jose Agustin Lopez Bueno (mailto:Agustin.Lopez@uv.es)

if [ $# -ne 3 ]
then
echo "Usage: $0 begindir filefilter whatfind"
echo " Search text in several files (recursively)"
echo " Example: $0 /tmp \"*.txt\" whatfind"
exit 1
fi

find "$1" -type f -name "$2" -print | while read i
do
grep -H -s -i $3 $i
done

-Script: renameall ----- Cut here -----------------
#! /bin/sh
# (c) Jose Agustin Lopez Bueno (mailto:Agustin.Lopez@uv.es)

if [ $# -ne 4 ]
then
echo "Usage: $0 begindir filefilter whatfind whatreplace"
echo " Rename several files (recursively)"
echo " Example: $0 /tmp \"*.*\" .jpg .jpeg"
exit 1
fi

find "$1" -name "$2" -print | while read i
do
mv $i `echo $i | sed "s|$3|$4|g"`
done

-Script: replacetext ----- Cut here -----------------
#! /bin/sh
# (c) Jose Agustin Lopez Bueno (mailto:Agustin.Lopez@uv.es)

if [ $# -ne 4 ]
then
echo "Usage: $0 begindir filefilter whatfind whatreplace"
echo " Replace text in several files (recursively)"
echo " Example: $0 /tmp \"*.txt\" wrong right"
exit 1
fi

find "$1" -type f -name "$2" -print | while read i
do
sed "s|$3|$4|g" $i > $i.tmp && mv $i.tmp $i
done
-------------------------------------------------