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 11-16-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131

Code:
$ cat 13months_ago
#! /usr/bin/ksh

for input in 20071115 20071105 20070105 ; do

        year=${input%????}
        day=${input#??????}
        month=${input#????}
        month=${month%??}
        month=${month#0}
        day=${day#0}
        print -n $input $year $month $day

        ((year=year-1))
        ((month=month-1))
        if ((!month)) ; then
                ((year=year-1))
                month=12
        fi
        typeset -Z2 newday newmonth
        newday=$day
        newmonth=$month
        output=${year}${newmonth}${newday}
        print -- " -->" $year $month $day $output
done
exit 0
$ ./13months_ago
20071115 2007 11 15 --> 2006 10 15 20061015
20071105 2007 11 5 --> 2006 10 5 20061005
20070105 2007 1 5 --> 2005 12 5 20051205
$