Highlight the current date in cal

caldatehighlighting

I would like to highlight today's date in the output of the cal command. What is the best way?

This is what I have so far:

cal -m | grep -C6 --color "$(date +%e)"

but it doesn't work for all cases e.g, when the date has a single digit. I also want the highlighting to work when I display the calendar for a year.

Best Answer

I don't know how to highlight the day in the year calendar cal -y with just regular expressions, but the reason your example was not working for single digit dates is because $(date +%e) prepends a space to the output when the date has a single digit.

This will work:

cal | grep --color -EC6 "\b$(date +%e | sed "s/ //g")"
Related Question