Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
1  
what specific version of UNIX are you using and what is the output of echo $TERM ? –  jamespo Apr 11 '11 at 14:09
    
Red Hat Linux / BSD Cal. –  dogbane Apr 11 '11 at 14:20
    
"BSD Cal" is the output of echo $TERM ? –  jamespo Apr 11 '11 at 15:21
    
$TERM is linux. –  dogbane Apr 11 '11 at 17:10
    
What version of Red Hat and cal, e.g. cat /etc/redhat-release and rpm -q util-linux. This works out of the box on recent versions of Ubuntu and Fedora, so presumably you are using an old version. –  Mikel Apr 12 '11 at 2:57

3 Answers 3

It may be fairly complicated to do something like this;
Why not try something like pal?

share|improve this answer

On my system (openSUSE 11.4, util-linux-2.19), the current date in output form cal is automatically highlighted (reverse colors) if the output goes to terminal. As per the manpage, this seems to be the default. If it does not work on your system, it might be a bug.

share|improve this answer
    
There are many variants of cal, for example all three BSDs have different features. This isn't a bug in dogbane's cal, just a different implementation. –  Gilles Apr 11 '11 at 19:59

The output is already highlighted, so you don't need to highlight it manually. In case you want it to work with grep, you need to disable it:

cal -mh | grep -C6 --color "$(date +%e)"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.