Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scripts works with awk 3.1.3 but not with 3.1.5

Status
Not open for further replies.

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
 
This should work:
Code:
LAST_DAY=`cal | awk '{last=$NF}END{print last}'`
 
i get no output? with either version of awk.
 
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}'
 
this works but could probably be better.
cal 10 2007 | awk NF | awk '{last=$NF}END{print last}'

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top