The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 05-28-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
You can try something like that :

Code:
filename=c15a

datestamp=$(date +%Y%m%d)
last_file=$(ls -1 $filename.$datestamp.* 2>/dev/null | tail -1)
if [ -z "$last_file" ]
then
  number=1
else
  number=$(( ${last_file##*.} + 1 ))
fi
new_filename=$(printf "%s.%s.%05.5d" "$filename" "$datestamp" "$number")

mv $filename $new_filename

Jean-Pierre.