Print last Sunday of month

This is a bash oneliner to get the date of the last Sunday in the month, nice to have if you cannot figure out an easy solution in crontab.

# cal -m | awk ‘{print $7}’ | grep -E ‘[0-9]’ | tail -n 1
28

or only using awk
# cal -m | awk ‘$7!=””{l=$7} END {print l}’
28

The cal command is run using the -m switch to have the first day of week to be Monday.

Leave a Reply