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!

AWK fun with dates 1

Status
Not open for further replies.

AnotherAlan

Technical User
Feb 10, 2006
362
GB
Hi all,

I'm trying to come up with an awk statement that will give me the first Monday in the month.
I've got this so far, but it fails when the Monday is the 1st of the month. And it's not very elegant.
cal | awk 'NF >=6 {print $2}' | head -2 | tail -1

My AWK skills are very poor and I'm trying to learn, but what I guess I need is a way of finding the first non-blank field of $2 after $2=="M".

All help appreciated.
Alan
 
OK this is not quite correct;
"way of finding the first non-blank field of $2 after $2=="M"."

It's more an issue of how to deal with the Sunday being unpopulated and therefore Mondays date being $1 not $2.

This is Solaris btw, and 12 2008 is where it is failing.

Thanks
 
cal month year | nawk 'NF>=6 && NR>=3{print $(NF-5);exit}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Many Thanks PH,

Best of all, I understand the logic.

Regards
Alan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top