Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename filename with the next seq number

Status
Not open for further replies.

shaokat

Technical User
Oct 8, 2002
11
IN
Can you help me figure out how to write a awk / ksh or any unix script for this:

Eg: File to move: filename0001.out

Listing of files found at the location:

filename0001.out
filename0002.out
filename0003.out

Result:

filename0001.out
filename0002.out
filename0003.out
filename0004.out <-The new file moved in this location should get moved with the next avaiable sequence number.

TIA,
 
Try :
Pass the filename to change as a parameter to :

#!/bin/ksh
LOGFILE=`echo ${1}|cut -c1-8`
NUM=`echo ${1}|cut -c9-12`
while [ -f ${LOGFILE}${NUM} ]
do
((NUM = $NUM+1))
done
NUM=`echo $NUM | awk '{printf(&quot;%04d&quot;, $0);}'`
> ${LOGFILE}${NUM}.out

HTH Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top