I’m trying to count how many weekends there are in a given month, but I can’t figure it out how to count them correctly… I thought ncal + grep commands would do the job, but they don’t work or I use AND with grep incorrectly.
I’m quite unclear on how we can achieve this with counting lines and AND please explain further. We are currently counting words per line where Su and Sa shows only once. eg:
$ ncal 5 2015
May 2015
Su 3 10 17 24 31
Mo 4 11 18 25
Tu 5 12 19 26
We 6 13 20 27
Th 7 14 21 28
Fr 1 8 15 22 29
Sa 2 9 16 23 30
I’m quite unclear on how we can achieve this with counting lines and AND please explain further. We are currently counting words per line where Su and Sa shows only once. eg:
$ ncal 5 2015
May 2015
Su 3 10 17 24 31
Mo 4 11 18 25
Tu 5 12 19 26
We 6 13 20 27
Th 7 14 21 28
Fr 1 8 15 22 29
Sa 2 9 16 23 30
Oh, that’s right… it’s quite unlogical. I figured that the good way out would be to check if the first day of month is Sunday and the last day is Saturday. If any of these two condition are met, then one weekend must be substracted. For example, february of 2015 starts on Sunday and ends on Saturday, so both conditions are met =>> 5-2=3 weekends. Am I right? I was looking at calendar and figured this out. Anyway, I don’t know how to write it.