Are you saying that there will never be a file01.dat in any of these directories?
Are all of the files in any given directory a contiguous numeric sequence starting with file02.dat? (I.e., could there just be file02.dat, file10.dat, and file11.dat in one of the directories?)
Are there ever any files other than fileXX.dat in the leaf directories?
Do we need to renumber files in directories that aren't leaves in the file system hierarchy?
Thanks for the help. When I awoke this morning I must have had a suddden rush of blood to the head and came up with this:
for DIR in fred*/bill*/tony/joe;
do
mv $DIR/filename02.dat $DIR/filename01.dat;
.
.
mv $DIR/filename12.dat $DIR/filename11.dat;
done
It does the job but if there is a more elegant solution I'd be interested to see it.
Actually the first line of the script deletes filename01.dat
there is a blank.dat which the last line copies to filename12.dat to complete the reset. As that is just a file containing "0" it could be located in /root which is where the script is located.
#!/bin/ksh
basedir=$(pwd)
for dir in fred*/bill*/tony/joe/
do
if ! cd "$dir"
then # No permission, or not-a-directory
printf "%s: %s not processed\n" "$0" "$dir" >&2
continue
fi
printf "%s: processing directory %s\n" "$0" "$dir"
target=file01.dat
src=2
while [ $src -le 12 ]
do
source=$(printf "file%02d.dat" $src)
if [ -e $source ]
then echo mv $source $target
else echo touch $target
fi
target=$source
src=$(( src + 1 ))
done
echo touch $target
cd "$basedir"
done
Remove the "echo " in all three places it occurs if you're convinced that this does what you want.
This creates empty files instead of files containing a "0" for file12.dat and any other missing files in the given directories. If you really want a file containing "0" (with no trailing <newline>), replace both touch $target commands with printf "0" > $target . If you want a more complicated initialization file, create it as a file named initfile.dat in the directory where this script will be started and replace the touch commands with cp "$basedir"/initfile.dat $target commands. If you want to be able to run this when you aren't sitting in the base directory for this file hierarchy, add cd rootdir (where "rootdir" is an absolute pathname to the desired starting point) before the line that sets basedir.