diff --git a/changesex.sh b/changesex.sh new file mode 100755 index 0000000000000000000000000000000000000000..0d7f152aac8e3d12227649169f9ab84dbcd7b875 --- /dev/null +++ b/changesex.sh @@ -0,0 +1,67 @@ +#! /bin/sh + +# +# Don't use a for loop, the number of files might exceed the +# command-line limit. +# +# This script changes albert to alberta and ALBERT to ALBERTA +# in _any_ regular file. +# +# + +ECHO= +while test $# -gt 0 ; do + case $1 in + DRYRUN) + set -x + ECHO=echo + ESC=\\ + ;; + REVERSE) + REVERSE=1 + ;; + LIST) + LIST=1 + ;; + *) + echo "The arguments must be DRYRUN, REVERSE or LIST" + exit 1 + ;; + esac + shift +done + + + +trap "rm -f /tmp/changesex.$$" 0 + +if test -z "$REVERSE"; then + cat > /tmp/changesex.$$ <<EOF +#! /bin/sh +F=\$1 +if ! echo \$F|grep -iqs "/CVS/" && \\ + ! grep -iqs alberta \$F && grep -iqs albert \$F ; then + echo "ALBERT -> ALBERTA in \$F" + if test -z "$LIST"; then + $ECHO sed -e 's/albert/alberta/g' -e 's/ALBERT/ALBERTA/g' \$F $ESC> \$F.new + $ECHO mv -f \$F.new \$F + fi +fi +EOF +else + cat > /tmp/changesex.$$ <<EOF +#! /bin/sh +F=\$1 +if ! echo \$F|grep -iqs "/CVS/" && grep -iqs alberta \$F ; then + echo "ALBERTA -> ALBERT in \$F" + if test -z "$LIST"; then + $ECHO sed -e 's/alberta/albert/g' -e 's/ALBERTA/ALBERT/g' \$F $ESC> \$F.new + $ECHO mv -f \$F.new \$F + fi +fi +EOF +fi +chmod +x /tmp/changesex.$$ + +find . \( -type f -a \! \( -name "*.new" -o -name ".*.new" \) \) -exec /tmp/changesex.$$ \{\} \; + \ No newline at end of file