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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Name file in sequence by last file 2

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I need a little bit of code to finish out my script....I have been here at work for over 24 hours and am brain dead now.....Pls help

I run my script, then the last bit I need to name the file off of the last file I saved plus 1 day.

Meaning, my output file is total_traffic and after the script runs, I go to the directory and rename it such as total_traffic-031002.

I run the script on different days, but I always run it in sequence. So the next time I run it I just name it for the next day. Like total_traffic-031102.

I just want the script to be able to look in the directory and use the next date format.

I appreciate the help as always!!!!

.//beaster
 
In shell:
date +'%m%d%y'
If your script is an awk script, pass the file date "suffix"
to the script and adjust the output file name accordingly

vlad
 
This (untested) awk script may be a useful starting point.
Code:
BEGIN { m[1]=31;m[2]=28;m[3]=31;m[4]=30;m[5]=31;m[6]=30;
        m[7]=31;m[8]=31;m[9]=30;m[10]=31;m[11]=30;m[12]=31;
}
{
 mm=substr($0,1,2)
 dd=substr($0,3,2)
 yy=substr($0,5,2)
 
 dd++;
 ddd = m[mm]
 if (mm==2 && yy%4 == 0) ddd=29
 if (dd>ddd) {
   dd = 1
   mm++;
   if (mm>12) {
     yy++;
     mm=1;
   }
  }
  printf ("%2.2d%2.2d%2.2d\n", mm, dd, yy)
}
Hope this helps. CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top