I have been doing files editing (using "vi") to change the period (e.g. 0902 to 0903) for 100 files each week as shown in the example below. I would like to have a script to solve this manual files editing. Please advice.
#!/bin/sh
# $1 directory
# $2 first string
# $3 string replacement
#Check we have the right number of arguments
if [ $# -ne 3 ]
then
usage
else
MYDIR=$1
echo "checking $MYDIR" #debug
for file in `ls $MYDIR/*`
do
echo "fixing $file"
echo "cp $file $file\_bak"|sed 's/\\_bak/_bak/'>tmp.sh
sh tmp.sh
echo "sed 's/$2/$3/g' $file >$file\_fix" |sed 's/\\_fix/_fix/'>tmp.sh
sh tmp.sh
echo "mv $file\_fix $file"|sed 's/\\_fix/_fix/'>tmp.sh
sh tmp.sh
done
fi