I'm writing a script in which I need to insert date/time stamps in exactly the same format as syslog (ie. %b %e %T). However, echo is eating the blank padded space for (%e).
I will insert the date/time stamp like this:
echo $DATE This is a date time stamp
and so have defined the DATE variable like this:
DATE=`date '+%b %e %T'`
This is where echo eats up the blank padded space.
If I were to insert the date/time stamp using "$DATE" instead of just $DATE, echo does not eat the spaces, but I don't want to do that and can't figure out how to include this in the actual DATE variable.
If I use sed (it's getting dirty and cumbersome now), I can do this (using echo -E $DATE):
DATE=`date '+%b %e %T' | sed 's/ /*/g'`
Which works as expected, but when I try and use an escaped space instead of an asterisk in the replacement text, it just won't work. Below, what I think should be being fed back to the echo command is:
but this is what I get instead:
DATE=`date '+%b %e %T' | sed 's/ /\\ /g'`
Nov 1 19:21:27
Any help would be appreciated.