Issue
I have the following script to highlight the current date in a calendar:
$ cal | grep --color -E6 "\b$(date +%e | sed 's/ //g')\b"
How can I cut a value with current date (output should be just the number of the current day: 2 or 02 in the example)? I need to use the "cal" function. Out:
2
This construction:
$ date +%d
does not satisfy the task condition, unfortunately.
Solution
If you just want today's date, why do you need cal
? Just use date +%e
.
But for what ever reason, if you want to only print the matched date with grep
, use -o
.
$ cal | grep --color=never -o "\b$(date +%e | tr -d ' ' )\b"
2
Or maybe you just want to trim the leading whitespace, in that case just use the date
& tr
command:
$ date +%e | tr -d ' '
2
Answered By - suvayu Answer Checked By - Timothy Miller (WPSolving Admin)