I need to count number of Sundays for a given month. For example if I want to get number of Sundays in DEC 2011 I do:
$ ncal -m 12 | grep Su | echo $(( `wc -w` - 1))
this returns 4. All good so far but I also need to do it for next year and I do not see to find an option for ncal to output only single month instead of whole year:
$ ncal -m 12 -y 2012
Is there any other way to get same result for next year without over-complicating things?
your command returns average Sundays per month for year 2012 = 4. The problem is I need this on per month basis so I would know how many Sundays are in the single month. There maybe 4 or 5 depends on the month. For example this is easy to do with ncal for a current year 2011: