Sep 17, 2007 #1 hodgins Technical User Sep 17, 2007 4 US script gives last day of the month with awk 3.1.3 but with awk 3.1.5 LAST_DAY is MT? #!/bin/ksh LAST_DAY=`cal | awk '{ if ( length($0) > 0 ) { end_of_month=$0 } } END { printf "%s\n",substr(end_of_month,length(end_of_month) -1 ) }'` echo $LAST_DAY
script gives last day of the month with awk 3.1.3 but with awk 3.1.5 LAST_DAY is MT? #!/bin/ksh LAST_DAY=`cal | awk '{ if ( length($0) > 0 ) { end_of_month=$0 } } END { printf "%s\n",substr(end_of_month,length(end_of_month) -1 ) }'` echo $LAST_DAY
Sep 17, 2007 #2 wakemeup Technical User Sep 17, 2007 2 US This should work: Code: LAST_DAY=`cal | awk '{last=$NF}END{print last}'` Upvote 0 Downvote
Sep 17, 2007 Thread starter #3 hodgins Technical User Sep 17, 2007 4 US i get no output? with either version of awk. Upvote 0 Downvote
Sep 17, 2007 Thread starter #4 hodgins Technical User Sep 17, 2007 4 US my bad that does work...for this month. what about a month that has a blank line at the end? cal 10 2007 | awk '{last=$NF}END{print last}' Upvote 0 Downvote
my bad that does work...for this month. what about a month that has a blank line at the end? cal 10 2007 | awk '{last=$NF}END{print last}'
Sep 17, 2007 Thread starter #5 hodgins Technical User Sep 17, 2007 4 US this works but could probably be better. cal 10 2007 | awk NF | awk '{last=$NF}END{print last}' Upvote 0 Downvote
Sep 17, 2007 #6 wakemeup Technical User Sep 17, 2007 2 US Code: LAST_DAY=`cal | awk 'NF{last=$NF}END{print last}'` Upvote 0 Downvote