How to remove a leading 0 from day of month?

July 6, 2011 at 14:16:33
Specs: UNIX
I need to compare dates and I am using the following code:
export TODAYSDATE=$(date +"%b %d") | sed 's/0//'
or
if [ $TEMPDATE = $(date +"%b %d") | sed 's/ 0//' ]; then
.... (write to a log file else do something else)
but it does not work. TODAYSDATE currently = 'Jul 06' and I want it to be 'Jul 6'.

See More: How to remove a leading 0 from day of month?

Report •

#1
July 6, 2011 at 15:29:44
Place command line substituion, $() , around the entire string:

export TODAYSDATE=$(date +"%b %d"| sed 's/0//' )


Report •

#2
July 6, 2011 at 15:34:17
Perfect!! Thank you! I've been messing with that all day... grrrr

Report •
Related Solutions


Ask Question