0

So, i trying to figure out ; How many months start with monday (being day 1 of the month) in a giving year.

right now i got

cal 2021 | awk '{ print $2 $9 $16}'

which displays all the mondays. I need to get rid of a few horizontal lines I tried a few variant of

cut

but it seems to only cut vertically.

1 Answers1

0

How many months start with monday (being day 1 of the month) in a giving year

For this purpose, the ncal mode of output (with the Mondays linewise rather than columnwise) is better suited - we can simply grep for all Mondays, then grep for day 1, and count the occurrences:

ncal 2021|grep Mo|grep -o ' 1 '|wc -l
Armali
  • 18,255
  • 14
  • 57
  • 171
  • The thing with ~~~ ncal 2021|grep Mo|grep -o ' 1 '|wc -l ~~~ You get all the ones. Something closer would be ~~~ (ncal -M -y YEAR | grep Mo | grep -c "1" ~~~ but for whatever reason, it shows 3 even for years that have 2. – still_noobin Feb 25 '21 at 23:57
  • Isn't to _get all the ones_ exactly what you asked for? Why do you think your variant would be _closer_? In fact, by omitting the spaces in the grep pattern, you introduced the error which causes always _3_ to be shown. Just copy and paste the command I gave, and if the output isn't correct, show it. – Armali Feb 26 '21 at 10:17