Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

date format - spaces not "0" in day

17 views
Skip to first unread message

ian diddams

unread,
Mar 8, 2013, 5:31:53 AM3/8/13
to
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.

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.

any ideas to do what I require?

cheers

ian

Joe Makowiec

unread,
Mar 8, 2013, 8:30:30 AM3/8/13
to
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/
0 new messages