#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <OLD> <NEW> <FileSuffix>" >&2
exit 1
fi
sourcename=$1
destinationname=$2
echo "Replacing $sourcename to $destinationname for all files with SUFFIX=$3 ..."
if [ -z "$3" ]
then
echo "\$3 is empty, set SUFFIX=sh"
SUFFIX=$3
else
echo "\$3 is NOT empty, set SUFFIX=$3"
SUFFIX=$3
fi
FILE="listfilename.tmp"
if [ -f $FILE ]; then
echo "File $FILE exists, removed."
rm -rf $FILE
else
echo "File $FILE does not exist, processing."
fi
LOGFILE="rename.sh.log"
if [ -f $LOGFILE ]; then
echo "File $LOGFILE exists, removed."
rm -rf $LOGFILE
else
echo "File $LOGFILE does not exist, processing."
touch $LOGFILE
fi
/usr/xpg4/bin/grep "$sourcename" *.$SUFFIX | cut -f1 -d : > $FILE
cat $FILE
while IFS= read -r line; do
/usr/xpg4/bin/sed 's/$sourcename/$destinationname/g' $line > $line.tmp && mv $line.tmp $line
echo "[$line] Replace $sourcename to $destinationname is completed successfully." >> $LOGFILE
done < $FILE
rm -rf $FILE
echo "All files are processed, please refer to the log file $LOGFILE ..."
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <OLD> <NEW> <FileSuffix>" >&2
exit 1
fi
sourcename=$1
destinationname=$2
echo "Replacing $sourcename to $destinationname for all files with SUFFIX=$3 ..."
if [ -z "$3" ]
then
echo "\$3 is empty, set SUFFIX=sh"
SUFFIX=$3
else
echo "\$3 is NOT empty, set SUFFIX=$3"
SUFFIX=$3
fi
FILE="listfilename.tmp"
if [ -f $FILE ]; then
echo "File $FILE exists, removed."
rm -rf $FILE
else
echo "File $FILE does not exist, processing."
fi
LOGFILE="rename.sh.log"
if [ -f $LOGFILE ]; then
echo "File $LOGFILE exists, removed."
rm -rf $LOGFILE
else
echo "File $LOGFILE does not exist, processing."
touch $LOGFILE
fi
/usr/xpg4/bin/grep "$sourcename" *.$SUFFIX | cut -f1 -d : > $FILE
cat $FILE
while IFS= read -r line; do
/usr/xpg4/bin/sed 's/$sourcename/$destinationname/g' $line > $line.tmp && mv $line.tmp $line
echo "[$line] Replace $sourcename to $destinationname is completed successfully." >> $LOGFILE
done < $FILE
rm -rf $FILE
echo "All files are processed, please refer to the log file $LOGFILE ..."