3

Every Mac comes with cal which shows a simple calendar of current month. Output is something like this:

   February 2014
Su Mo Tu We Th Fr Sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

I was wondering if we can use some sed and date magic and highlight today's number using ANSI escape sequences. I haven't tried anything because I don't know much about sed.

1
  • cal from bsdmainutils 8.2.3 already seems to be highlighting the current date.
    – Zelda
    Commented Feb 19, 2014 at 6:33

2 Answers 2

4

gcal(http://www.gnu.org/software/gcal/) is available from Homebrew and displays the current month with current day highlighted when invoked without any other args.

2

Try this:

$ cal | grep -w -A4 -B6 $(date +%d)

-A4 and -B6 flags of grep will print 4 lines after and 6 lines before the matching line.

5
  • This didn't work for me. For today, it printed this: pastebin.com/raw.php?i=gt0FrjF3
    – Mohsen
    Commented Feb 20, 2014 at 20:36
  • I tried this: cal | grep -A4 -B5 --color "\s$(date +%d)\s" and gave me good results. But I'm not sure if that works for first day of month or alike
    – Mohsen
    Commented Feb 20, 2014 at 20:41
  • @Mohsen Updated answer. This should work for all days.
    – Ketan
    Commented Feb 20, 2014 at 20:43
  • Ok, works good now. You might want to add --color flag because Mac's grep don't highlight by default
    – Mohsen
    Commented Feb 20, 2014 at 20:45
  • @Mohsen Thanks for the update. On my mac, I do not seem to need the --color flag. It works as it is.
    – Ketan
    Commented Feb 20, 2014 at 20:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .