I'm looking for a way to get the nth day of mth week of a month based on the "cal" command:
Meaning the following:
$ cal 11 2001|cat -n
1 November 2001
2 S M Tu W Th F S
3 1 2 3
4 4 5 6 7 8 9 10
5 11 12 13 14 15 16 17
6 18 19 20 21 22 23 24
7 25 26 27 28 29 30
8
What i want, is to say " I want the 3rd day of week 4 ( with the cat -n that would be 6).
I'm looking for a comand using the awk command
looking something like:
cal 11 2001|cat -n|grep "my_week( here is 6)"|awk 'my function of awk ', so the output would be:
tuesday 20th november...
#! /usr/bin/ksh
year=$1
month=$2
week=$3
day=$4
set -A days Sun Mon Tue Wed Thu Fri Sat
set -A months XXX Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
cal $month $year
#
# Get date of last day in 1st week of month
dldw1=$(cal $month $year | sed -n '3s/. //gp')
#
# calculate what day-of-month is day/week
if [[ $week = 1 ]] ; then
((dom=day))
else
((dom=day+dldw1+((week-2)*7)))
fi
#
# Calculate day of week
((dow = (dom+dldw1)%7 ))
#
# All done...print it out
echo ${months[month]} ${dom}, $year is on ${days[dow]}
exit 0