Because in the last days of the month, '0 friday' could fall in the next month so $trymonth would never be equal to $thismonth. No?
Because in the last days of the month, '0 friday' could fall in the next month so $trymonth would never be equal to $thismonth. No?
Yes, in the days after the last Friday, but not on that last Friday. No? E.g the last Friday is 29th of this month. Your script will still work on this day, but not on 30th.
Sorry, last fridays date of the month is what you asked for, I see you wanted the date of the last friday in the month
Catch me on Freenode - imark
This also works for me
cal 03 2013 | awk 'NR==1 {m=substr($1, 1, 3); y=$2} NF>5 {d=$6} END {print "Friday", m, d, y}'
Combining this with the code suggested by diesch, I get
Just for fun, the same in sed:Code:ncal -h|awk 'NR==1{m=substr($1,1,3);y=$2}/^Fr/{print"Friday,",m,$NF,y}'
Code:ncal -h|sed -nr '1h;/^Fr/{G;s/.*( \w+) *\n *(\w{3})\w*/Friday, \2\1/p}'
Last edited by schragge; March 29th, 2013 at 07:18 PM.
Bookmarks