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")"
You could use sed
for that.
$ cal|sed -e '1n;s/\(..\)\(.\)/\1,\2/g'
May 2012
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, 29, 30, 31
1n
prints the first line and moves to the next. The replacement then takes the chars three by three and prints the first two followed by ,
then the third.
Best Answer
The following prints the current date with a reversed field which is replaced in cal by sed.