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-26-2009
colemar colemar is offline
Registered User
  
 

Join Date: Apr 2009
Location: Trento, Italy
Posts: 116
Quote:
Originally Posted by aronmelon View Post
Is there a way to Create file name for the prior Sunday of the run_date
This is not trivial.
Possible solutions include perl, ksh93, GNU date command, GNU awk.

GNU date:
Code:
last_sunday_yyyymmdd=$(date -d "-$(date +%w) days" +%Y%m%d)
day_of_run=20090523
prior_sunday_yyyymmdd=$(date -d "$day_of_run -$(date -d $day_of_run +%w) days" +%Y%m%d)
GNU awk:
Code:
last_sunday_yyyymmdd=$(awk 'BEGIN{print strftime("%Y%m%d",systime()-86400*strftime("%w",systime()))}')

Last edited by colemar; 05-26-2009 at 06:48 PM..