On 08 Mar 2013 in linux.redhat, ian diddams wrote:
> I am using
>
> date +"%b %d"
>
> to return a string something like
>
> Mar 08
>
> BUT
>
> what I really need is it to return
>
> Mar 8
>
> i.e. the leading zero on the date replaced by a space.
>
> any ideas to do what I require?
[joe@myserver ~]$ man date
DATE(1) User Commands
NAME
date - print or set the system date and time
SYNOPSIS
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
...
FORMAT controls the output. Interpreted sequences are:
...
%d day of month (e.g., 01)
%e day of month, space padded; same as %_d
...
By default, date pads numeric fields with zeroes. The following
optional flags may follow `%':
- (hyphen) do not pad the field
_ (underscore) pad with spaces
> I could use a simple sed on the string but the problem I then have
> is that it would also turn "Mar 10" into "Mar 1 " - which is not
> what I need.
Could you use a regex which specifies a leading 0 followed by a digit?
--
Joe Makowiec
http://makowiec.org/
Email:
http://makowiec.org/contact/?Joe
Usenet Improvement Project:
http://twovoyagers.com/improve-usenet.org/