#----define a file to hold the counter
COUNTFILE=count.txt
#----create the counter if file does not exist
if [ ! -f $COUNTFILE ]
then
echo 0 > $COUNTFILE
fi
#----define a function to update and return the counter
function get_count {
awk '{
c=$1;
if (c==99999) c=0;
c++;
printf "%05d",c
} END {
print c > FILENAME}' $COUNTFILE
}
#----use a loop to rename *.dat files
for file in *.dat
do
mv $file ${file%.dat}$(get_count).dat
done
One problem that I need to get around. Basically, I need to ftp a list of candidate files. However, before I pull them, I need to assign each a unique sequence number as described in my above post. I have defined the get_count function earlier in the script.
If I do this:
while f=$(line)
do
ftp ${args} ${ip} <<-EOF
user ${id} ${pwd}
rename $f.DAT $f${get_count}.DONE
get $f$(get_count).DONE
quit
EOF
done < ${file}_good.tmp
Then it will again assign a new ssequence number during the "get" command. How can I define the sequence number so I "get" the same file name that I created during the reanme step.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.